Skip to content

Commit c1d6e40

Browse files
authored
Add shamaton/msgpackgen to benchmarks and update shamaton/msgpack (alecthomas#93)
1 parent d31a9d4 commit c1d6e40

File tree

7 files changed

+1242
-129
lines changed

7 files changed

+1242
-129
lines changed

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This is necessary due to the use of two conflicting generator commands for capnproto
22
.NOTPARALLEL:
33

4-
all: Colfer.go FlatBufferA.go msgp_gen.go structdef-gogo.pb.go structdef.pb.go structdef.capnp.go structdef.capnp2.go gencode.schema.gen.go gencode-unsafe.schema.gen.go structdefxdr_generated.go structdef-bebop.go
4+
all: Colfer.go FlatBufferA.go msgp_gen.go structdef-gogo.pb.go structdef.pb.go structdef.capnp.go structdef.capnp2.go gencode.schema.gen.go gencode-unsafe.schema.gen.go structdefxdr_generated.go structdef-bebop.go structdef_msgpackgen.go
55

66
Colfer.go:
77
go run github.com/pascaldekloe/colfer/cmd/colf go
@@ -43,13 +43,15 @@ gencode-unsafe.schema.gen.go: gencode-unsafe.schema
4343
structdefxdr_generated.go: structdefxdr.go
4444
go run github.com/calmh/xdr/cmd/genxdr -o structdefxdr_generated.go structdefxdr.go
4545

46-
structdef-bebop.go:
46+
structdef-bebop.go:
4747
bebopc-go -i structdef-bebop.bop -o structdef-bebop.go --package goserbench
4848

49+
structdef_msgpackgen.go: structdef.go
50+
go run github.com/shamaton/msgpackgen -input-file structdef.go -output-file structdef_msgpackgen.go -strict
51+
4952
.PHONY: clean
5053
clean:
51-
rm -f Colfer.go FlatBufferA.go msgp_gen.go structdef-gogo.pb.go structdef.pb.go structdef.capnp.go structdef.capnp2.go gencode.schema.gen.go gencode-unsafe.schema.gen.go structdefxdr_generated.go
52-
54+
rm -f Colfer.go FlatBufferA.go msgp_gen.go structdef-gogo.pb.go structdef.pb.go structdef.capnp.go structdef.capnp2.go gencode.schema.gen.go gencode-unsafe.schema.gen.go structdefxdr_generated.go structdef_msgpackgen.go
5355
.PHONY: install
5456
install:
5557
go get -u github.com/gogo/protobuf/protoc-gen-gogofaster
@@ -75,3 +77,4 @@ install:
7577
go get -u github.com/niubaoshu/gotiny
7678
go get -u github.com/200sc/bebop
7779
go get -u github.com/200sc/bebop/main/bebopc-go
80+
go get -u github.com/shamaton/msgpackgen

README.md

Lines changed: 120 additions & 110 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/alecthomas/go_serialization_benchmarks
33
go 1.13
44

55
require (
6-
github.com/Hatch1fy/errors v0.1.0 // indirect
76
github.com/200sc/bebop v0.0.8
87
github.com/DataDog/zstd v1.4.5 // indirect
8+
github.com/Hatch1fy/errors v0.1.0 // indirect
99
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863
1010
github.com/alecthomas/binary v0.0.0-20171101084825-6e8df1b1fb9d
1111
github.com/andyleap/gencode v0.0.0-20171124163308-e1423834d4b4 // indirect
@@ -37,6 +37,8 @@ require (
3737
github.com/prysmaticlabs/go-bitfield v0.0.0-20190825002834-fb724e897364 // indirect
3838
github.com/prysmaticlabs/go-ssz v0.0.0-20190827151743-72881c4223d8
3939
github.com/shamaton/msgpack v1.1.1
40+
github.com/shamaton/msgpack/v2 v2.0.0
41+
github.com/shamaton/msgpackgen v0.1.1
4042
github.com/tinylib/msgp v1.1.0
4143
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 // indirect
4244
github.com/ugorji/go/codec v1.1.7

go.sum

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
github.com/Hatch1fy/errors v0.1.0 h1:O0eV+wlv/uF++/IQFxPaTVQOCHxzEXFFX0cMrIs8GSs=
2-
github.com/Hatch1fy/errors v0.1.0/go.mod h1:ghvTU0wQ49AH7DcAfdKmWjBDjgEOoc1ltdPhDlGPz7w=
31
github.com/200sc/bebop v0.0.8 h1:rBxUorlPWyUjR+J99PaYcjc9CZYCdeDg/Na+HbznPdI=
42
github.com/200sc/bebop v0.0.8/go.mod h1:fCmYqE/nuhgRpN0ttqh913jWZH5yKpv0o8009Tke8jM=
53
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
64
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
5+
github.com/Hatch1fy/errors v0.1.0 h1:O0eV+wlv/uF++/IQFxPaTVQOCHxzEXFFX0cMrIs8GSs=
6+
github.com/Hatch1fy/errors v0.1.0/go.mod h1:ghvTU0wQ49AH7DcAfdKmWjBDjgEOoc1ltdPhDlGPz7w=
77
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863 h1:BRrxwOZBolJN4gIwvZMJY1tzqBvQgpaZiQRuIDD40jM=
88
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM=
99
github.com/alecthomas/binary v0.0.0-20171101084825-6e8df1b1fb9d h1:ndgr53uGotk3W0l6njh0jusaJw8+ZwZn8EKnx8QauJk=
@@ -14,6 +14,8 @@ github.com/andyleap/parser v0.0.0-20160126201130-db5a13a7cd46 h1:t5xfxrFvtVIPcpt
1414
github.com/andyleap/parser v0.0.0-20160126201130-db5a13a7cd46/go.mod h1:optl5aMZUO+oj3KCDaQ0WYQMP6QhUQXXDAHQnCA3wI8=
1515
github.com/calmh/xdr v1.1.0 h1:U/Dd4CXNLoo8EiQ4ulJUXkgO1/EyQLgDKLgpY1SOoJE=
1616
github.com/calmh/xdr v1.1.0/go.mod h1:E8sz2ByAdXC8MbANf1LCRYzedSnnc+/sXXJs/PVqoeg=
17+
github.com/dave/jennifer v1.4.1 h1:XyqG6cn5RQsTj3qlWQTKlRGAyrTcsk1kUmWdZBzRjDw=
18+
github.com/dave/jennifer v1.4.1/go.mod h1:7jEdnm+qBcxl8PC0zyp7vxcpSRnzXSt9r39tpTVGlwA=
1719
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1820
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1921
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892 h1:qg9VbHo1TlL0KDM0vYvBG9EY0X0Yku5WYIPoFWt8f6o=
@@ -89,6 +91,11 @@ github.com/prysmaticlabs/go-ssz v0.0.0-20190827151743-72881c4223d8 h1:EzplWlL5Ut
8991
github.com/prysmaticlabs/go-ssz v0.0.0-20190827151743-72881c4223d8/go.mod h1:VecIJZrewdAuhVckySLFt2wAAHRME934bSDurP8ftkc=
9092
github.com/shamaton/msgpack v1.1.1 h1:wZcK/aIifWvsDl6jXo+c/tRYo9Vnb8abWCossDbj2Ww=
9193
github.com/shamaton/msgpack v1.1.1/go.mod h1:ibiaNQRTCUISAYkkyOpaSCEBiCAxXe6u6Mu1sQ6945U=
94+
github.com/shamaton/msgpack v1.2.1 h1:40cwW7YAEdOIxcxIsUkAxSMUyYWZUyNiazI5AyiBntI=
95+
github.com/shamaton/msgpack/v2 v2.0.0 h1:qaFDySYUa5LPaWNBQc9wA72YGaNts86aW9364i8ztGM=
96+
github.com/shamaton/msgpack/v2 v2.0.0/go.mod h1:aTUEmh31ziGX1Ml7wMPLVY0f4vT3CRsCvZRoSCs+VGg=
97+
github.com/shamaton/msgpackgen v0.1.1 h1:Aq+uhF53vaYO0kDgsEt4O+ogE1tU3okB0SyhnNllAzo=
98+
github.com/shamaton/msgpackgen v0.1.1/go.mod h1:IPBa+TaqE5H+APs+KuHNlYpMTnhQTLmb84qyJYdlzFQ=
9299
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
93100
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
94101
github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=

serialization_benchmarks_test.go

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import (
2525
easyjson "github.com/mailru/easyjson"
2626
"github.com/niubaoshu/gotiny"
2727
ssz "github.com/prysmaticlabs/go-ssz"
28-
shamaton "github.com/shamaton/msgpack"
28+
shamaton "github.com/shamaton/msgpack/v2"
29+
shamatongen "github.com/shamaton/msgpackgen/msgpack"
2930
"github.com/tinylib/msgp/msgp"
3031
"github.com/ugorji/go/codec"
3132
vmihailenco "github.com/vmihailenco/msgpack/v4"
@@ -1310,11 +1311,11 @@ func BenchmarkIkeaUnmarshal(b *testing.B) {
13101311
type ShamatonMapMsgpackSerializer struct{}
13111312

13121313
func (m ShamatonMapMsgpackSerializer) Marshal(o interface{}) ([]byte, error) {
1313-
return shamaton.EncodeStructAsMap(o)
1314+
return shamaton.MarshalAsMap(o)
13141315
}
13151316

13161317
func (m ShamatonMapMsgpackSerializer) Unmarshal(d []byte, o interface{}) error {
1317-
return shamaton.DecodeStructAsMap(d, o)
1318+
return shamaton.UnmarshalAsMap(d, o)
13181319
}
13191320

13201321
func BenchmarkShamatonMapMsgpackMarshal(b *testing.B) {
@@ -1330,11 +1331,11 @@ func BenchmarkShamatonMapMsgpackUnmarshal(b *testing.B) {
13301331
type ShamatonArrayMsgpackSerializer struct{}
13311332

13321333
func (m ShamatonArrayMsgpackSerializer) Marshal(o interface{}) ([]byte, error) {
1333-
return shamaton.EncodeStructAsArray(o)
1334+
return shamaton.MarshalAsArray(o)
13341335
}
13351336

13361337
func (m ShamatonArrayMsgpackSerializer) Unmarshal(d []byte, o interface{}) error {
1337-
return shamaton.DecodeStructAsArray(d, o)
1338+
return shamaton.UnmarshalAsArray(d, o)
13381339
}
13391340

13401341
func BenchmarkShamatonArrayMsgpackMarshal(b *testing.B) {
@@ -1345,6 +1346,44 @@ func BenchmarkShamatonArrayMsgpackUnmarshal(b *testing.B) {
13451346
benchUnmarshal(b, ShamatonArrayMsgpackSerializer{})
13461347
}
13471348

1349+
// github.com/shamaton/msgpackgen - as map
1350+
1351+
type ShamatonMapMsgpackgenSerializer struct{}
1352+
1353+
func (m ShamatonMapMsgpackgenSerializer) Marshal(o interface{}) ([]byte, error) {
1354+
return shamatongen.MarshalAsMap(o)
1355+
}
1356+
func (m ShamatonMapMsgpackgenSerializer) Unmarshal(d []byte, o interface{}) error {
1357+
return shamatongen.UnmarshalAsMap(d, o)
1358+
}
1359+
func BenchmarkShamatonMapMsgpackgenMarshal(b *testing.B) {
1360+
RegisterGeneratedResolver()
1361+
benchMarshal(b, ShamatonMapMsgpackgenSerializer{})
1362+
}
1363+
func BenchmarkShamatonMapMsgpackgenUnmarshal(b *testing.B) {
1364+
RegisterGeneratedResolver()
1365+
benchUnmarshal(b, ShamatonMapMsgpackgenSerializer{})
1366+
}
1367+
1368+
// github.com/shamaton/msgpackgen - as array
1369+
1370+
type ShamatonArrayMsgpackgenSerializer struct{}
1371+
1372+
func (m ShamatonArrayMsgpackgenSerializer) Marshal(o interface{}) ([]byte, error) {
1373+
return shamatongen.MarshalAsArray(o)
1374+
}
1375+
func (m ShamatonArrayMsgpackgenSerializer) Unmarshal(d []byte, o interface{}) error {
1376+
return shamatongen.UnmarshalAsArray(d, o)
1377+
}
1378+
func BenchmarkShamatonArrayMsgpackgenMarshal(b *testing.B) {
1379+
RegisterGeneratedResolver()
1380+
benchMarshal(b, ShamatonArrayMsgpackgenSerializer{})
1381+
}
1382+
func BenchmarkShamatonArrayMsgpackgenUnmarshal(b *testing.B) {
1383+
RegisterGeneratedResolver()
1384+
benchUnmarshal(b, ShamatonArrayMsgpackgenSerializer{})
1385+
}
1386+
13481387
// github.com/prysmaticlabs/go-ssz
13491388

13501389
func generateNoTimeNoStringNoFloatA() []*NoTimeNoStringNoFloatA {

stats.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ fi
88

99
cat results.txt | awk -F' ' '
1010
BEGIN {
11-
print "benchmark | iter | time/iter | bytes/op | allocs/op |tt.sec | tt.kb | ns/alloc"
12-
print "---------------------------------------------|-------|-----------|-----------|------------|--------|--------------|-----------"
11+
print "benchmark | iter | time/iter | bytes/op | allocs/op | tt.sec | tt.kb | ns/alloc"
12+
print "----------------------------------------------|------------|--------------|-----------|------------|--------|--------------|-----------"
1313
}
1414
1515
/Benchmark/ {
1616
gsub(/ +/," ",$0)
1717
if ($7 != 0) {
18-
printf "%-40s | %10d | %6d %s | %5d | %3d | %6.2f | %7d | %7.2f\n",$1,$2,$3,$4,$5,$7,$2*$3/1000000000,$2*$5/10000,$3/$7
18+
printf "%-45s | %10d | %6d %s | %9d | %10d | %6.2f | %12d | %7.2f\n",$1,$2,$3,$4,$5,$7,$2*$3/1000000000,$2*$5/10000,$3/$7
1919
}else{
20-
printf "%-40s | %10d | %6d %s | %5d | %3d | %6.2f | %7d | %7.2f\n",$1,$2,$3,$4,$5,$7,$2*$3/1000000000,$2*$5/10000,0
20+
printf "%-45s | %10d | %6d %s | %9d | %10d | %6.2f | %12d | %7.2f\n",$1,$2,$3,$4,$5,$7,$2*$3/1000000000,$2*$5/10000,0
2121
}
2222
gsub(/(Unm|M)arshal/,"",$1)
2323
pname[$1]=$1
@@ -48,11 +48,11 @@ function arr_sort(arr,number) {
4848
END {
4949
print "\n"
5050
print "Totals:\n\n"
51-
print "benchmark | iter | time/iter | bytes/op | allocs/op |tt.sec | tt.kb | ns/alloc"
52-
print "---------------------------------------------|-------|-----------|-----------|------------|--------|--------------|-----------"
51+
print "benchmark | iter | time/iter | bytes/op | allocs/op | tt.sec | tt.kb | ns/alloc"
52+
print "-----------------------------------------|------------|--------------|-----------|------------|--------|--------------|-----------"
5353
for (p in pname) {
5454
pr=pname[p]
55-
arry[proto[pr,3]] = sprintf("%-40s | %10d | %6d %s | %5d | %3d | %6.2f | %7d | %7.2f",pr,proto[pr,2],proto[pr,3],proto[pr,4],proto[pr,5],proto[pr,7],
55+
arry[proto[pr,3]] = sprintf("%-40s | %10d | %6d %s | %9d | %10d | %6.2f | %12d | %7.2f",pr,proto[pr,2],proto[pr,3],proto[pr,4],proto[pr,5],proto[pr,7],
5656
proto[pr,2]*proto[pr,3]/1000000000,proto[pr,2]*proto[pr,5]/10000,proto[pr,3]/proto[pr,7])
5757
}
5858
arr_sort(arry,keys)

0 commit comments

Comments
 (0)