Skip to content

Commit

Permalink
fasttape: copi module renamed to fastape (alecthomas#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarifard authored Jun 11, 2024
1 parent 6992cb1 commit 8c09655
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 96 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This is a test suite for benchmarking various Go serialization methods.
- [github.com/mus-format/mus-go](https://github.com/mus-format/mus-go)
- [wellquite.org/bebop](https://fossil.wellquite.org/bebop) (generated code)
- [github.com/deneonet/benc](https://github.com/deneonet/benc)
- [github.com/nazarifard/fastape](https://github.com/nazarifard/fastape)

## Running the benchmarks

Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ require (
wellquite.org/bebop v0.0.0-20231109192402-a92af83691ec
)

require github.com/nazarifard/copi v0.0.0-20240609072615-763316f77579 // indirect
require (
github.com/nazarifard/copi v0.0.0-20240609072615-763316f77579 // indirect
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b // indirect
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ github.com/mus-format/mus-go v0.0.0-20230426134740-6572513fca3d/go.mod h1:zdDnTF
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nazarifard/copi v0.0.0-20240609072615-763316f77579 h1:toqD8/J9DygfET+HZRsIu4kLUz32E4qcUhR1USRNPrY=
github.com/nazarifard/copi v0.0.0-20240609072615-763316f77579/go.mod h1:RZX6PlUi+vF52MjBneuJcoszjuejOPWdMnAKaJOccGc=
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b h1:Roh7HBLqAxLpo/qxWztQlzt6QUBGTCX9AXxCaJf+pB8=
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b/go.mod h1:F54tpGg4uMgsYNUqD07iNENNGcS2GJobr+td/iZ5Xm4=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/niubaoshu/goutils v0.0.0-20180828035119-e8e576f66c2b h1:T7vmCmpGIvqlOOp5SXatALP+HYc/40ZHbxmgy+p+sN0=
Expand Down
91 changes: 0 additions & 91 deletions internal/serializers/copi/copi.go

This file was deleted.

91 changes: 91 additions & 0 deletions internal/serializers/fastape/fastape.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package fastape

import (
"github.com/alecthomas/go_serialization_benchmarks/goserbench"
"github.com/nazarifard/fastape"
)

type smallStructTape struct {
NameTape fastape.StringTape
BirthDayTape fastape.TimeTape
PhoneTape fastape.StringTape
SiblingsTape fastape.UnitTape[int]
SpouseTape fastape.UnitTape[bool]
MoneyTape fastape.UnitTape[float64]
}

func (cp smallStructTape) Sizeof(p goserbench.SmallStruct) int {
return cp.NameTape.Sizeof(p.Name) +
cp.BirthDayTape.Sizeof(p.BirthDay) +
cp.PhoneTape.Sizeof(p.Phone) +
cp.SiblingsTape.Sizeof(p.Siblings) +
cp.SpouseTape.Sizeof(p.Spouse) +
cp.MoneyTape.Sizeof(p.Money)
}

func (cp smallStructTape) Marshal(o interface{}) (buf []byte, err error) {
p := o.(*goserbench.SmallStruct)
buf = make([]byte, cp.Sizeof(*p))

k, n := 0, 0
k, _ = cp.NameTape.Marshal(p.Name, buf[n:])
n += k
k, _ = cp.BirthDayTape.Marshal(p.BirthDay, buf[n:])
n += k
k, _ = cp.PhoneTape.Marshal(p.Phone, buf[n:])
n += k
k, _ = cp.SiblingsTape.Marshal(p.Siblings, buf[n:])
n += k
k, _ = cp.SpouseTape.Marshal(p.Spouse, buf[n:])
n += k
k, _ = cp.MoneyTape.Marshal(p.Money, buf[n:])
n += k
return
}

func (cp smallStructTape) Unmarshal(bs []byte, o interface{}) (err error) {
p := o.(*goserbench.SmallStruct)

k, n := 0, 0
k, err = cp.NameTape.Unmarshal(bs[n:], &p.Name)
n += k
if err != nil {
return err
}

k, err = cp.BirthDayTape.Unmarshal(bs[n:], &p.BirthDay)
n += k
if err != nil {
return err
}

k, err = cp.PhoneTape.Unmarshal(bs[n:], &p.Phone)
n += k
if err != nil {
return err
}

k, err = cp.SiblingsTape.Unmarshal(bs[n:], &p.Siblings)
n += k
if err != nil {
return err
}

k, err = cp.SpouseTape.Unmarshal(bs[n:], &p.Spouse)
n += k
if err != nil {
return err
}

k, err = cp.MoneyTape.Unmarshal(bs[n:], &p.Money)
n += k
if err != nil {
return err
}

return
}

func NewTape() goserbench.Serializer {
return smallStructTape{}
}
8 changes: 4 additions & 4 deletions serialization_benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/bson"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/capnproto"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/colfer"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/copi"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/easyjson"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/fastape"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/fastjson"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/flatbuffers"
"github.com/alecthomas/go_serialization_benchmarks/internal/serializers/gencode"
Expand Down Expand Up @@ -233,9 +233,9 @@ var benchmarkCases = []BenchmarkCase{
URL: "",
New: baseline.NewBaselineSerializer,
}, {
Name: "copi",
URL: "github.com/nazarifard/copi",
New: copi.NewCopiSerializer,
Name: "fastape",
URL: "github.com/nazarifard/fastape",
New: fastape.NewTape,
},
}

Expand Down

0 comments on commit 8c09655

Please sign in to comment.