goserbench

package module
v0.0.0-...-6a8ce33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 14 Imported by: 0

README

Benchmarks of Go serialization methods

This is a test suite for benchmarking various Go serialization methods.

Tested serialization methods

Excluded Serializers

Given existed benchmark by alecthomas,the below serializers are excluded from this test because of their poor performance.

Running the benchmarks

go get -u -t
go test -bench='.*' ./

Shameless plug: I use pawk to format the table:

go test -bench='.*' ./ | pawk -F'\t' '"%-40s %10s %10s %s %s" % f'

Recommendation

If performance, correctness and interoperability are the most important factors, gogoprotobuf is currently the best choice. It does require a pre-processing step (eg. via Go 1.4's "go generate" command).

But as always, make your own choice based on your requirements.

Data

The data being serialized is the following structure with randomly generated values:

type A struct {
    Name     string
    BirthDay time.Time
    Phone    string
    Siblings int
    Spouse   bool
    Money    float64
}

Results

2019-02-27 Results with Go 1.11 on a Thinkpad T410:

benchmark                                      iter    time/iter   bytes/op     allocs/op  tt.time   tt.bytes
---------                                      ----    ---------   --------     ---------  -------   --------
BenchmarkGotinyMarshal-4                   10000000    184 ns/op     0 B/op   0 allocs/op   1.84 s       0 KB
BenchmarkGotinyUnmarshal-4                  3000000    497 ns/op   112 B/op   3 allocs/op   1.49 s   33600 KB
BenchmarkGotinyNoTimeMarshal-4             10000000    183 ns/op     0 B/op   0 allocs/op   1.83 s       0 KB
BenchmarkGotinyNoTimeUnmarshal-4            3000000    465 ns/op    96 B/op   3 allocs/op   1.40 s   28800 KB
BenchmarkMsgpMarshal-4                      5000000    363 ns/op   128 B/op   1 allocs/op   1.81 s   64000 KB
BenchmarkMsgpUnmarshal-4                    2000000    591 ns/op   112 B/op   3 allocs/op   1.18 s   22400 KB
BenchmarkVmihailencoMsgpackMarshal-4         500000   3251 ns/op   368 B/op   6 allocs/op   1.63 s   18400 KB
BenchmarkVmihailencoMsgpackUnmarshal-4       500000   3768 ns/op   384 B/op  13 allocs/op   1.88 s   19200 KB
BenchmarkJsonMarshal-4                       500000   3606 ns/op   304 B/op   4 allocs/op   1.80 s   15200 KB
BenchmarkJsonUnmarshal-4                     200000   7351 ns/op   359 B/op   7 allocs/op   1.47 s    7180 KB
BenchmarkJsonIterMarshal-4                   500000   3455 ns/op   312 B/op   5 allocs/op   1.73 s   15600 KB
BenchmarkJsonIterUnmarshal-4                 500000   3142 ns/op   248 B/op   7 allocs/op   1.57 s   12400 KB
BenchmarkEasyJsonMarshal-4                   500000   3129 ns/op   784 B/op   5 allocs/op   1.56 s   39200 KB
BenchmarkEasyJsonUnmarshal-4                1000000   2349 ns/op   160 B/op   4 allocs/op   2.35 s   16000 KB
BenchmarkBsonMarshal-4                       500000   2264 ns/op   392 B/op  10 allocs/op   1.13 s   19600 KB
BenchmarkBsonUnmarshal-4                     500000   3081 ns/op   244 B/op  19 allocs/op   1.54 s   12200 KB
BenchmarkGobMarshal-4                       1000000   1383 ns/op    48 B/op   2 allocs/op   1.38 s    4800 KB
BenchmarkGobUnmarshal-4                     1000000   1482 ns/op   112 B/op   3 allocs/op   1.48 s   11200 KB
BenchmarkUgorjiCodecMsgpackMarshal-4         500000   3097 ns/op  1280 B/op   4 allocs/op   1.55 s   64000 KB
BenchmarkUgorjiCodecMsgpackUnmarshal-4      1000000   2685 ns/op   464 B/op   5 allocs/op   2.69 s   46400 KB
BenchmarkUgorjiCodecBincMarshal-4            500000   3314 ns/op  1328 B/op   5 allocs/op   1.66 s   66400 KB
BenchmarkUgorjiCodecBincUnmarshal-4          500000   3419 ns/op   704 B/op   8 allocs/op   1.71 s   35200 KB
BenchmarkFlatBuffersMarshal-4               3000000    521 ns/op     0 B/op   0 allocs/op   1.56 s       0 KB
BenchmarkFlatBuffersUnmarshal-4             3000000    508 ns/op   112 B/op   3 allocs/op   1.52 s   33600 KB
BenchmarkProtobufMarshal-4                  1000000   1494 ns/op   200 B/op   7 allocs/op   1.49 s   20000 KB
BenchmarkProtobufUnmarshal-4                1000000   1377 ns/op   192 B/op  10 allocs/op   1.38 s   19200 KB
BenchmarkGoprotobufMarshal-4                2000000    699 ns/op    96 B/op   2 allocs/op   1.40 s   19200 KB
BenchmarkGoprotobufUnmarshal-4              1000000   1173 ns/op   200 B/op  10 allocs/op   1.17 s   20000 KB
BenchmarkGogoprotobufMarshal-4              5000000    314 ns/op    64 B/op   1 allocs/op   1.57 s   32000 KB
BenchmarkGogoprotobufUnmarshal-4            3000000    448 ns/op    96 B/op   3 allocs/op   1.34 s   28800 KB
BenchmarkColferMarshal-4                    5000000    259 ns/op    64 B/op   1 allocs/op   1.29 s   32000 KB
BenchmarkColferUnmarshal-4                  3000000    405 ns/op   112 B/op   3 allocs/op   1.22 s   33600 KB
BenchmarkGencodeMarshal-4                   5000000    337 ns/op    80 B/op   2 allocs/op   1.69 s   40000 KB
BenchmarkGencodeUnmarshal-4                 3000000    398 ns/op   112 B/op   3 allocs/op   1.19 s   33600 KB
BenchmarkGencodeUnsafeMarshal-4            10000000    201 ns/op    48 B/op   1 allocs/op   2.01 s   48000 KB
BenchmarkGencodeUnsafeUnmarshal-4           5000000    344 ns/op    96 B/op   3 allocs/op   1.72 s   48000 KB
BenchmarkXDR2Marshal-4                      5000000    331 ns/op    64 B/op   1 allocs/op   1.66 s   32000 KB
BenchmarkXDR2Unmarshal-4                   10000000    246 ns/op    32 B/op   2 allocs/op   2.46 s   32000 KB
BenchmarkIkeaMarshal-4                      1000000   1066 ns/op    72 B/op   8 allocs/op   1.07 s    7200 KB
BenchmarkIkeaUnmarshal-4                    1000000   1464 ns/op   160 B/op  11 allocs/op   1.46 s   16000 KB
BenchmarkShamatonMapMsgpackMarshal-4        1000000   1338 ns/op   208 B/op   4 allocs/op   1.34 s   20800 KB
BenchmarkShamatonMapMsgpackUnmarshal-4      1000000   1188 ns/op   144 B/op   3 allocs/op   1.19 s   14400 KB
BenchmarkShamatonArrayMsgpackMarshal-4      1000000   1185 ns/op   176 B/op   4 allocs/op   1.19 s   17600 KB
BenchmarkShamatonArrayMsgpackUnmarshal-4    2000000    873 ns/op   144 B/op   3 allocs/op   1.75 s   28800 KB
---
totals:
BenchmarkGencodeUnsafe-4                   15000000    545 ns/op   144 B/op   4 allocs/op   8.18 s  216000 KB  136.25 ns/alloc
BenchmarkXDR2-4                            15000000    577 ns/op    96 B/op   3 allocs/op   8.65 s  144000 KB  192.33 ns/alloc
BenchmarkGotinyNoTime-4                    13000000    648 ns/op    96 B/op   3 allocs/op   8.42 s  124800 KB  216.00 ns/alloc
BenchmarkColfer-4                           8000000    664 ns/op   176 B/op   4 allocs/op   5.31 s  140800 KB  166.00 ns/alloc
BenchmarkGotiny-4                          13000000    681 ns/op   112 B/op   3 allocs/op   8.85 s  145600 KB  227.00 ns/alloc
BenchmarkGencode-4                          8000000    735 ns/op   192 B/op   5 allocs/op   5.88 s  153600 KB  147.00 ns/alloc
BenchmarkGogoprotobuf-4                     8000000    762 ns/op   160 B/op   4 allocs/op   6.10 s  128000 KB  190.50 ns/alloc
BenchmarkMsgp-4                             7000000    954 ns/op   240 B/op   4 allocs/op   6.68 s  168000 KB  238.50 ns/alloc
BenchmarkFlatBuffers-4                      6000000   1029 ns/op   112 B/op   3 allocs/op   6.17 s   67200 KB  343.00 ns/alloc
BenchmarkGoprotobuf-4                       3000000   1872 ns/op   296 B/op  12 allocs/op   5.62 s   88800 KB  156.00 ns/alloc
BenchmarkShamatonArrayMsgpack-4             3000000   2058 ns/op   320 B/op   7 allocs/op   6.17 s   96000 KB  294.00 ns/alloc
BenchmarkShamatonMapMsgpack-4               2000000   2526 ns/op   352 B/op   7 allocs/op   5.05 s   70400 KB  360.86 ns/alloc
BenchmarkIkea-4                             2000000   2530 ns/op   232 B/op  19 allocs/op   5.06 s   46400 KB  133.16 ns/alloc
BenchmarkGob-4                              2000000   2865 ns/op   160 B/op   5 allocs/op   5.73 s   32000 KB  573.00 ns/alloc
BenchmarkProtobuf-4                         2000000   2871 ns/op   392 B/op  17 allocs/op   5.74 s   78400 KB  168.88 ns/alloc
BenchmarkBson-4                             1000000   5345 ns/op   636 B/op  29 allocs/op   5.34 s   63600 KB  184.31 ns/alloc
BenchmarkEasyJson-4                         1500000   5478 ns/op   944 B/op   9 allocs/op   8.22 s  141600 KB  608.67 ns/alloc
BenchmarkUgorjiCodecMsgpack-4               1500000   5782 ns/op  1744 B/op   9 allocs/op   8.67 s  261600 KB  642.44 ns/alloc
BenchmarkJsonIter-4                         1000000   6597 ns/op   560 B/op  12 allocs/op   6.60 s   56000 KB  549.75 ns/alloc
BenchmarkUgorjiCodecBinc-4                  1000000   6733 ns/op  2032 B/op  13 allocs/op   6.73 s  203200 KB  517.92 ns/alloc
BenchmarkVmihailencoMsgpack-4               1000000   7019 ns/op   752 B/op  19 allocs/op   7.02 s   75200 KB  369.42 ns/alloc
BenchmarkJson-4                              700000  10957 ns/op   663 B/op  11 allocs/op   7.67 s   46410 KB  996.09 ns/alloc

Documentation

Overview

Package goserbench is a generated protocol buffer package.

It is generated from these files:
	structdef-gogo.proto

It has these top-level messages:
	GogoProtoBufA

Package goserbench is a generated protocol buffer package.

It is generated from these files:

structdef.proto

It has these top-level messages:

ProtoBufA

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthStructdefGogo = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowStructdefGogo   = fmt.Errorf("proto: integer overflow")
)

Functions

func FlatBufferAAddBirthDay

func FlatBufferAAddBirthDay(builder *flatbuffers.Builder, birthDay int64)

func FlatBufferAAddMoney

func FlatBufferAAddMoney(builder *flatbuffers.Builder, money float64)

func FlatBufferAAddName

func FlatBufferAAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT)

func FlatBufferAAddPhone

func FlatBufferAAddPhone(builder *flatbuffers.Builder, phone flatbuffers.UOffsetT)

func FlatBufferAAddSiblings

func FlatBufferAAddSiblings(builder *flatbuffers.Builder, siblings int32)

func FlatBufferAAddSpouse

func FlatBufferAAddSpouse(builder *flatbuffers.Builder, spouse byte)

func FlatBufferAEnd

func FlatBufferAEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT

func FlatBufferAStart

func FlatBufferAStart(builder *flatbuffers.Builder)

Types

type A

type A struct {
	Name     string
	BirthDay time.Time
	Phone    string
	Siblings int
	Spouse   bool
	Money    float64
}

func (*A) DecodeMsg

func (z *A) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*A) EncodeMsg

func (z *A) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*A) MarshalEasyJSON

func (v *A) MarshalEasyJSON(w *jwriter.Writer)

func (*A) MarshalJSONEasyJSON

func (v *A) MarshalJSONEasyJSON() ([]byte, error)

func (*A) MarshalMsg

func (z *A) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*A) Msgsize

func (z *A) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*A) UnmarshalEasyJSON

func (v *A) UnmarshalEasyJSON(l *jlexer.Lexer)

func (*A) UnmarshalJSONEasyJSON

func (v *A) UnmarshalJSONEasyJSON(data []byte) error

func (*A) UnmarshalMsg

func (z *A) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ColferA

type ColferA struct {
	Name     string
	BirthDay time.Time
	Phone    string
	Siblings int32
	Spouse   bool
	Money    float64
}

func (*ColferA) MarshalBinary

func (o *ColferA) MarshalBinary() (data []byte, err error)

MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return is always nil.

func (*ColferA) MarshalLen

func (o *ColferA) MarshalLen() int

MarshalLen returns the Colfer serial byte size.

func (*ColferA) MarshalTo

func (o *ColferA) MarshalTo(buf []byte) int

MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.

func (*ColferA) UnmarshalBinary

func (o *ColferA) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, goserbench.ColferError, and goserbench.ColferContinue.

type ColferContinue

type ColferContinue int

ColferContinue signals a data continuation as a byte index.

func (ColferContinue) Error

func (i ColferContinue) Error() string

type ColferError

type ColferError int

ColferError signals a data mismatch as as a byte index.

func (ColferError) Error

func (i ColferError) Error() string

type FlatBufferA

type FlatBufferA struct {
	// contains filtered or unexported fields
}

func (*FlatBufferA) BirthDay

func (rcv *FlatBufferA) BirthDay() int64

func (*FlatBufferA) Init

func (rcv *FlatBufferA) Init(buf []byte, i flatbuffers.UOffsetT)

func (*FlatBufferA) Money

func (rcv *FlatBufferA) Money() float64

func (*FlatBufferA) Name

func (rcv *FlatBufferA) Name() []byte

func (*FlatBufferA) Phone

func (rcv *FlatBufferA) Phone() []byte

func (*FlatBufferA) Siblings

func (rcv *FlatBufferA) Siblings() int32

func (*FlatBufferA) Spouse

func (rcv *FlatBufferA) Spouse() byte

type GencodeA

type GencodeA struct {
	Name     string
	BirthDay time.Time
	Phone    string
	Siblings int64
	Spouse   bool
	Money    float64
}

func (*GencodeA) Marshal

func (d *GencodeA) Marshal(buf []byte) ([]byte, error)

func (*GencodeA) Size

func (d *GencodeA) Size() (s uint64)

func (*GencodeA) Unmarshal

func (d *GencodeA) Unmarshal(buf []byte) (uint64, error)

type GencodeUnsafeA

type GencodeUnsafeA struct {
	Name     string
	BirthDay int64
	Phone    string
	Siblings int64
	Spouse   bool
	Money    float64
}

func (*GencodeUnsafeA) Marshal

func (d *GencodeUnsafeA) Marshal(buf []byte) ([]byte, error)

func (*GencodeUnsafeA) Size

func (d *GencodeUnsafeA) Size() (s uint64)

func (*GencodeUnsafeA) Unmarshal

func (d *GencodeUnsafeA) Unmarshal(buf []byte) (uint64, error)

type GogoProtoBufA

type GogoProtoBufA struct {
	Name     string  `protobuf:"bytes,1,req,name=name" json:"name"`
	BirthDay int64   `protobuf:"varint,2,req,name=birthDay" json:"birthDay"`
	Phone    string  `protobuf:"bytes,3,req,name=phone" json:"phone"`
	Siblings int32   `protobuf:"varint,4,req,name=siblings" json:"siblings"`
	Spouse   bool    `protobuf:"varint,5,req,name=spouse" json:"spouse"`
	Money    float64 `protobuf:"fixed64,6,req,name=money" json:"money"`
}

func (*GogoProtoBufA) Descriptor

func (*GogoProtoBufA) Descriptor() ([]byte, []int)

func (*GogoProtoBufA) GetBirthDay

func (m *GogoProtoBufA) GetBirthDay() int64

func (*GogoProtoBufA) GetMoney

func (m *GogoProtoBufA) GetMoney() float64

func (*GogoProtoBufA) GetName

func (m *GogoProtoBufA) GetName() string

func (*GogoProtoBufA) GetPhone

func (m *GogoProtoBufA) GetPhone() string

func (*GogoProtoBufA) GetSiblings

func (m *GogoProtoBufA) GetSiblings() int32

func (*GogoProtoBufA) GetSpouse

func (m *GogoProtoBufA) GetSpouse() bool

func (*GogoProtoBufA) Marshal

func (m *GogoProtoBufA) Marshal() (data []byte, err error)

func (*GogoProtoBufA) MarshalTo

func (m *GogoProtoBufA) MarshalTo(data []byte) (int, error)

func (*GogoProtoBufA) ProtoMessage

func (*GogoProtoBufA) ProtoMessage()

func (*GogoProtoBufA) Reset

func (m *GogoProtoBufA) Reset()

func (*GogoProtoBufA) Size

func (m *GogoProtoBufA) Size() (n int)

func (*GogoProtoBufA) String

func (m *GogoProtoBufA) String() string

func (*GogoProtoBufA) Unmarshal

func (m *GogoProtoBufA) Unmarshal(data []byte) error

type NoTimeA

type NoTimeA struct {
	Name     string
	BirthDay int64
	Phone    string
	Siblings int
	Spouse   bool
	Money    float64
}

func (*NoTimeA) DecodeMsg

func (z *NoTimeA) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*NoTimeA) EncodeMsg

func (z *NoTimeA) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*NoTimeA) MarshalMsg

func (z *NoTimeA) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*NoTimeA) Msgsize

func (z *NoTimeA) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*NoTimeA) UnmarshalMsg

func (z *NoTimeA) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ProtoBufA

type ProtoBufA struct {
	Name             *string  `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
	BirthDay         *int64   `protobuf:"varint,2,req,name=birthDay" json:"birthDay,omitempty"`
	Phone            *string  `protobuf:"bytes,3,req,name=phone" json:"phone,omitempty"`
	Siblings         *int32   `protobuf:"varint,4,req,name=siblings" json:"siblings,omitempty"`
	Spouse           *bool    `protobuf:"varint,5,req,name=spouse" json:"spouse,omitempty"`
	Money            *float64 `protobuf:"fixed64,6,req,name=money" json:"money,omitempty"`
	XXX_unrecognized []byte   `json:"-"`
}

func (*ProtoBufA) Descriptor

func (*ProtoBufA) Descriptor() ([]byte, []int)

func (*ProtoBufA) GetBirthDay

func (m *ProtoBufA) GetBirthDay() int64

func (*ProtoBufA) GetMoney

func (m *ProtoBufA) GetMoney() float64

func (*ProtoBufA) GetName

func (m *ProtoBufA) GetName() string

func (*ProtoBufA) GetPhone

func (m *ProtoBufA) GetPhone() string

func (*ProtoBufA) GetSiblings

func (m *ProtoBufA) GetSiblings() int32

func (*ProtoBufA) GetSpouse

func (m *ProtoBufA) GetSpouse() bool

func (*ProtoBufA) ProtoMessage

func (*ProtoBufA) ProtoMessage()

func (*ProtoBufA) Reset

func (m *ProtoBufA) Reset()

func (*ProtoBufA) String

func (m *ProtoBufA) String() string

type XDRA

type XDRA struct {
	Name     string
	BirthDay int64
	Phone    string
	Siblings int32
	Spouse   bool
	Money    uint64
}

func (XDRA) MarshalXDR

func (o XDRA) MarshalXDR() ([]byte, error)

func (XDRA) MarshalXDRInto

func (o XDRA) MarshalXDRInto(m *xdr.Marshaller) error

func (XDRA) MustMarshalXDR

func (o XDRA) MustMarshalXDR() []byte

func (*XDRA) UnmarshalXDR

func (o *XDRA) UnmarshalXDR(bs []byte) error

func (*XDRA) UnmarshalXDRFrom

func (o *XDRA) UnmarshalXDRFrom(u *xdr.Unmarshaller) error

func (XDRA) XDRSize

func (o XDRA) XDRSize() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL