Skip to content

Commit

Permalink
restore idr/reuse becnhmark (#171)
Browse files Browse the repository at this point in the history
* restore idr/ruse and simply code

* refresh benchmark report data
  • Loading branch information
chmike authored Jun 29, 2024
1 parent 241d7c2 commit a57448d
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 339 deletions.
8 changes: 8 additions & 0 deletions benchmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ var benchmarkCases = []BenchmarkCase{
URL: "github.com/chmike/ditp",
New: idr.NewIDRSerializer,

TimeSupport: TSFullTzOffset,
APIKind: AKManual,
Notes: []string{"low level IDR encoding demo with same nsec time encoding as benc"},
}, {
Name: "idr/reuse",
URL: "github.com/chmike/ditp",
New: idr.NewIDRSerializerReuse,

BufferReuseMarshal: true,
TimeSupport: TSFullTzOffset,
APIKind: AKManual,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Sereal/Sereal v0.0.0-20230201113653-fa72c87b650e
github.com/alecthomas/binary v0.0.0-20221018225505-74871811ee56
github.com/calmh/xdr v1.1.0
github.com/chmike/ditp v0.0.0-20240618130435-627cf7ce9ad6
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cybriq/gotiny v0.0.5
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
github.com/calmh/xdr v1.1.0 h1:U/Dd4CXNLoo8EiQ4ulJUXkgO1/EyQLgDKLgpY1SOoJE=
github.com/calmh/xdr v1.1.0/go.mod h1:E8sz2ByAdXC8MbANf1LCRYzedSnnc+/sXXJs/PVqoeg=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/chmike/ditp v0.0.0-20240618130435-627cf7ce9ad6 h1:FIQLUAh5cGcvt6Sm4wD2TUbDDJjCnmpv1A/lnJDBMh0=
github.com/chmike/ditp v0.0.0-20240618130435-627cf7ce9ad6/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
github.com/chmike/ditp v0.0.0-20240621105623-1fe3e031524f h1:fxT+cPh0H+xo8ojX5O1zt/o/vTf7oeKdpk7r7asg2fs=
github.com/chmike/ditp v0.0.0-20240621105623-1fe3e031524f/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd h1:ImEBzQdUJ6jx65nsFrBlNNV8um9lW4ApGEa+mIjXOZQ=
github.com/chmike/ditp v0.0.0-20240629115045-1ab5bbd646cd/go.mod h1:Az8w1aHUmNFs7+C7v41Y/cpXIBafvOs+7J7M/KGsM1c=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down
14 changes: 5 additions & 9 deletions internal/serializers/idr/idr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@ func (s IDRSerializer) Marshal(o interface{}) ([]byte, error) {
e := make([]byte, 0, 64)
e = low.PutTime(e, v.BirthDay)
e = low.PutFloat64(e, v.Money)
e = low.PutInt32(e, int32(v.Siblings))
e = low.PutBool(e, v.Spouse)
e = low.PutVarInt(e, v.Siblings)
e = low.PutString(e, v.Name)
e = low.PutString(e, v.Phone)
return e, nil
}

func (s IDRSerializer) Unmarshal(d []byte, o interface{}) (err error) {
v := o.(*goserbench.SmallStruct)
_ = d[29]
d, v.BirthDay = low.Time(d)
d, v.Money = low.Float64(d)
d, v1 := low.Int32(d)
v.Siblings = int(v1)
d, v.Spouse = low.Bool(d)
d, v.Siblings = low.VarInt(d)
d, v.Name = low.String(d, 1<<14)
_, v.Phone = low.String(d, 20)
return nil
}

func NewIDRSerializer() goserbench.Serializer {
return IDRSerializer{} // set initial buffer to 256 bytes
return IDRSerializer{}
}

type IDRSerializerReuse struct {
Expand All @@ -46,21 +44,19 @@ func (s IDRSerializerReuse) Marshal(o interface{}) ([]byte, error) {
e := low.Reset(s.e)
e = low.PutTime(e, v.BirthDay)
e = low.PutFloat64(e, v.Money)
e = low.PutInt32(e, int32(v.Siblings))
e = low.PutBool(e, v.Spouse)
e = low.PutVarInt(e, v.Siblings)
e = low.PutString(e, v.Name)
e = low.PutString(e, v.Phone)
return e, nil
}

func (s IDRSerializerReuse) Unmarshal(d []byte, o interface{}) (err error) {
v := o.(*goserbench.SmallStruct)
_ = d[29]
d, v.BirthDay = low.Time(d)
d, v.Money = low.Float64(d)
d, v1 := low.Int32(d)
v.Siblings = int(v1)
d, v.Spouse = low.Bool(d)
d, v.Siblings = low.VarInt(d)
d, v.Name = low.String(d, 1<<14)
_, v.Phone = low.String(d, 20)
return nil
Expand Down
Loading

0 comments on commit a57448d

Please sign in to comment.