Skip to content

Commit 29cc2b3

Browse files
authored
1 parent ab78a27 commit 29cc2b3

File tree

7 files changed

+446
-125
lines changed

7 files changed

+446
-125
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ structdefxdr_generated.go: structdefxdr.go
4646
structdef-bebop.go:
4747
go run github.com/200sc/bebop/main/bebopc-go@latest -i structdef-bebop.bop -o structdef-bebop.go --package goserbench
4848

49+
structdef-bebop-wellquite.go: structdef-bebop-wellquite.bop
50+
go run wellquite.org/bebop/cmd/bebop -i ./structdef-bebop-wellquite.bop -o ./structdef-bebop-wellquite.go -p github.com/alecthomas/go_serialization_benchmarks/goserbench
51+
4952
structdef_msgpackgen.go: structdef.go
5053
go run github.com/shamaton/msgpackgen@latest -input-file structdef.go -output-file structdef_msgpackgen.go -strict
5154

@@ -79,4 +82,6 @@ install:
7982
go install github.com/200sc/bebop/main/bebopc-go@latest
8083
go install github.com/shamaton/msgpackgen@latest
8184
go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest
82-
go install github.com/mus-format/mus-go@latest
85+
go install github.com/mus-format/mus-go@latest
86+
go install wellquite.org/bebop@latest
87+
go install wellquite.org/bebop/cmd/bebop@latest

README.md

Lines changed: 128 additions & 124 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
go.mongodb.org/mongo-driver v1.11.1
3232
google.golang.org/protobuf v1.28.1
3333
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
34+
wellquite.org/bebop v0.0.0-20231109192402-a92af83691ec
3435
zombiezen.com/go/capnproto2 v2.18.2+incompatible
3536
)
3637

@@ -42,6 +43,7 @@ require (
4243
github.com/glycerine/rbtree v0.0.0-20190406191118-ceb71889d809 // indirect
4344
github.com/golang/snappy v0.0.4 // indirect
4445
github.com/google/go-cmp v0.5.9 // indirect
46+
github.com/google/uuid v1.3.1 // indirect
4547
github.com/gopherjs/gopherjs v0.0.0-20210603182125-eeedf4a0e899 // indirect
4648
github.com/gorilla/websocket v1.4.2 // indirect
4749
github.com/josharian/intern v1.0.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi
102102
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
103103
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
104104
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
105+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
106+
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
105107
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
106108
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
107109
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
@@ -486,5 +488,7 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
486488
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
487489
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
488490
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
491+
wellquite.org/bebop v0.0.0-20231109192402-a92af83691ec h1:3j/3/IhEeN/0RznBr02KK4HcI99hH3EmszBsYSDTIe8=
492+
wellquite.org/bebop v0.0.0-20231109192402-a92af83691ec/go.mod h1:Q/g7VwYAUv9QrjR2BIxSA25YarXMDGDPa8lrLAJx9UI=
489493
zombiezen.com/go/capnproto2 v2.18.2+incompatible h1:v3BD1zbruvffn7zjJUU5Pn8nZAB11bhZSQC4W+YnnKo=
490494
zombiezen.com/go/capnproto2 v2.18.2+incompatible/go.mod h1:XO5Pr2SbXgqZwn0m0Ru54QBqpOf4K5AYBO+8LAOBQEQ=

serialization_benchmarks_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,76 @@ func Benchmark_Bebop_Unmarshal(b *testing.B) {
16521652
}
16531653
}
16541654

1655+
// wellquite.org/bebop
1656+
1657+
func generateBebopWellquite() []BebopBufWellquite {
1658+
structs := make([]BebopBufWellquite, 1000)
1659+
for idx := range structs {
1660+
structs[idx] = BebopBufWellquite{
1661+
Name: randString(16),
1662+
// bebop does support times, but as 100-nanosecond ticks, losing some precision
1663+
BirthDay: time.Now().Round(100 * time.Nanosecond),
1664+
Phone: randString(10),
1665+
Siblings: rand.Int31n(5),
1666+
Spouse: rand.Intn(2) == 1,
1667+
Money: rand.Float64(),
1668+
}
1669+
}
1670+
return structs
1671+
}
1672+
1673+
func Benchmark_Bebop_Wellquite_Marshal(b *testing.B) {
1674+
structs := generateBebopWellquite()
1675+
length := len(structs)
1676+
var serialSize int
1677+
b.ReportAllocs()
1678+
b.ResetTimer()
1679+
for iteration := 0; iteration < b.N; iteration++ {
1680+
out, err := structs[rand.Intn(length)].MarshalBebop(nil)
1681+
if err != nil {
1682+
b.Fatal(err)
1683+
}
1684+
serialSize += len(out)
1685+
}
1686+
b.ReportMetric(float64(serialSize)/float64(b.N), "B/serial")
1687+
}
1688+
1689+
func Benchmark_Bebop_Wellquite_Unmarshal(b *testing.B) {
1690+
b.StopTimer()
1691+
structs := generateBebopWellquite()
1692+
length := len(structs)
1693+
serialized := make([][]byte, length)
1694+
var serialSize int
1695+
for idx, value := range structs {
1696+
bites, err := value.MarshalBebop(nil)
1697+
if err != nil {
1698+
b.Fatal(err)
1699+
}
1700+
serialized[idx] = bites
1701+
serialSize += len(bites)
1702+
}
1703+
b.ReportMetric(float64(serialSize)/float64(length), "B/serial")
1704+
b.ReportAllocs()
1705+
b.StartTimer()
1706+
1707+
for iteration := 0; iteration < b.N; iteration++ {
1708+
idx := rand.Intn(length)
1709+
decoded := BebopBufWellquite{}
1710+
_, err := decoded.UnmarshalBebop(serialized[idx])
1711+
if err != nil {
1712+
b.Fatalf("bebop2 failed to unmarshal: %s (%s)", err, serialized[idx])
1713+
}
1714+
// Validate unmarshalled data.
1715+
if validate != "" {
1716+
value := structs[idx]
1717+
correct := decoded.Name == value.Name && decoded.BirthDay == value.BirthDay && decoded.Phone == value.Phone && decoded.Siblings == value.Siblings && decoded.Spouse == value.Spouse && decoded.Money == value.Money
1718+
if !correct {
1719+
b.Fatalf("unmarshaled object differed:\n%v\n%v", value, decoded)
1720+
}
1721+
}
1722+
}
1723+
}
1724+
16551725
// github.com/valyala/fastjson
16561726

16571727
func generateFastJsonA() []*fastjson.Value {

structdef-bebop-wellquite.bop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct BebopBufWellquite {
2+
string Name;
3+
date BirthDay;
4+
string Phone;
5+
int32 Siblings;
6+
bool Spouse;
7+
float64 Money;
8+
}

structdef-bebop-wellquite.go

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)