Skip to content

restore idr/reuse becnhmark #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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