Skip to content

Commit a57448d

Browse files
authored
restore idr/reuse becnhmark (#171)
* restore idr/ruse and simply code * refresh benchmark report data
1 parent 241d7c2 commit a57448d

File tree

5 files changed

+345
-339
lines changed

5 files changed

+345
-339
lines changed

benchmarks.go

+8
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@ var benchmarkCases = []BenchmarkCase{
460460
URL: "github.com/chmike/ditp",
461461
New: idr.NewIDRSerializer,
462462

463+
TimeSupport: TSFullTzOffset,
464+
APIKind: AKManual,
465+
Notes: []string{"low level IDR encoding demo with same nsec time encoding as benc"},
466+
}, {
467+
Name: "idr/reuse",
468+
URL: "github.com/chmike/ditp",
469+
New: idr.NewIDRSerializerReuse,
470+
463471
BufferReuseMarshal: true,
464472
TimeSupport: TSFullTzOffset,
465473
APIKind: AKManual,

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/Sereal/Sereal v0.0.0-20230201113653-fa72c87b650e
88
github.com/alecthomas/binary v0.0.0-20221018225505-74871811ee56
99
github.com/calmh/xdr v1.1.0
10-
github.com/chmike/ditp v0.0.0-20240618130435-627cf7ce9ad6
10+
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd
1111
github.com/cosmos/cosmos-proto v1.0.0-beta.3
1212
github.com/cybriq/gotiny v0.0.5
1313
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
3434
github.com/calmh/xdr v1.1.0 h1:U/Dd4CXNLoo8EiQ4ulJUXkgO1/EyQLgDKLgpY1SOoJE=
3535
github.com/calmh/xdr v1.1.0/go.mod h1:E8sz2ByAdXC8MbANf1LCRYzedSnnc+/sXXJs/PVqoeg=
3636
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
37-
github.com/chmike/ditp v0.0.0-20240618130435-627cf7ce9ad6 h1:FIQLUAh5cGcvt6Sm4wD2TUbDDJjCnmpv1A/lnJDBMh0=
38-
github.com/chmike/ditp v0.0.0-20240618130435-627cf7ce9ad6/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
37+
github.com/chmike/ditp v0.0.0-20240621105623-1fe3e031524f h1:fxT+cPh0H+xo8ojX5O1zt/o/vTf7oeKdpk7r7asg2fs=
38+
github.com/chmike/ditp v0.0.0-20240621105623-1fe3e031524f/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
39+
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd h1:ImEBzQdUJ6jx65nsFrBlNNV8um9lW4ApGEa+mIjXOZQ=
40+
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
3941
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
4042
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
4143
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=

internal/serializers/idr/idr.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,26 @@ func (s IDRSerializer) Marshal(o interface{}) ([]byte, error) {
1313
e := make([]byte, 0, 64)
1414
e = low.PutTime(e, v.BirthDay)
1515
e = low.PutFloat64(e, v.Money)
16-
e = low.PutInt32(e, int32(v.Siblings))
1716
e = low.PutBool(e, v.Spouse)
17+
e = low.PutVarInt(e, v.Siblings)
1818
e = low.PutString(e, v.Name)
1919
e = low.PutString(e, v.Phone)
2020
return e, nil
2121
}
2222

2323
func (s IDRSerializer) Unmarshal(d []byte, o interface{}) (err error) {
2424
v := o.(*goserbench.SmallStruct)
25-
_ = d[29]
2625
d, v.BirthDay = low.Time(d)
2726
d, v.Money = low.Float64(d)
28-
d, v1 := low.Int32(d)
29-
v.Siblings = int(v1)
3027
d, v.Spouse = low.Bool(d)
28+
d, v.Siblings = low.VarInt(d)
3129
d, v.Name = low.String(d, 1<<14)
3230
_, v.Phone = low.String(d, 20)
3331
return nil
3432
}
3533

3634
func NewIDRSerializer() goserbench.Serializer {
37-
return IDRSerializer{} // set initial buffer to 256 bytes
35+
return IDRSerializer{}
3836
}
3937

4038
type IDRSerializerReuse struct {
@@ -46,21 +44,19 @@ func (s IDRSerializerReuse) Marshal(o interface{}) ([]byte, error) {
4644
e := low.Reset(s.e)
4745
e = low.PutTime(e, v.BirthDay)
4846
e = low.PutFloat64(e, v.Money)
49-
e = low.PutInt32(e, int32(v.Siblings))
5047
e = low.PutBool(e, v.Spouse)
48+
e = low.PutVarInt(e, v.Siblings)
5149
e = low.PutString(e, v.Name)
5250
e = low.PutString(e, v.Phone)
5351
return e, nil
5452
}
5553

5654
func (s IDRSerializerReuse) Unmarshal(d []byte, o interface{}) (err error) {
5755
v := o.(*goserbench.SmallStruct)
58-
_ = d[29]
5956
d, v.BirthDay = low.Time(d)
6057
d, v.Money = low.Float64(d)
61-
d, v1 := low.Int32(d)
62-
v.Siblings = int(v1)
6358
d, v.Spouse = low.Bool(d)
59+
d, v.Siblings = low.VarInt(d)
6460
d, v.Name = low.String(d, 1<<14)
6561
_, v.Phone = low.String(d, 20)
6662
return nil

0 commit comments

Comments
 (0)