Home

Awesome

go-serialization-benchmarks

In this benchmarks:

Benchmarks

Fastest Safe

NAMEITERATIONS COUNTNS/OPB/SIZEB/OPALLOCS/OP
mus1408238280.5558481
bebop200sc1302831685.5261481
benc1180293394.8160481
protobuf_mus668845616369481
vtprotobuf6871676191.3691923
protobuf2460066503.1702714
json42177726971506009
gob66589178801599407233

Fastest Unsafe

NAMEITERATIONS COUNTNS/OPB/SIZEB/OPALLOCS/OP
mus18103663575800
benc1482966969.766000
protobuf_mus8152317129.46900
vtprotobuf7640108165.6691442

All

NAMEITERATIONS COUNTNS/OPB/SIZEB/OPALLOCS/OP
mus+reuse+unsafe18103663575800
benc+raw+reuse+unsafestr1482966969.766000
mus+notunsafe+reuse1408238280.5558481
mus+unsafe1490809881.7258641
bebop200sc+notunsafe+reuse1302831685.5261481
benc+raw+unsafestr1269120192.6360641
mus+raw+reuse1201614292.9858481
benc+raw+reuse1180293394.8160481
bebop200sc+notunsafe10276396108611122
mus+raw+reuse+varint9901872112.259481
mus+notunsafe12403351113.3581122
mus+raw9719802122581122
benc+raw10587306122.1641122
protobuf_mus+reuse+unsafe8152317129.46900
mus+raw+varint8684614144.8591122
protobuf_mus+raw+reuse668845616369481
vtprotobuf+raw+reuse+unsafeunm7640108165.6691442
vtprotobuf+raw+reuse+unsafeunm+varint7736064174.1701442
protobuf_mus+raw+reuse+varint589156318670481
protobuf_mus+unsafe6586830187.469791
vtprotobuf+raw+reuse6871676191.3691923
protobuf_mus+native+reuse+unsafe6588710194.1691442
vtprotobuf+raw+reuse+varint6774465198.3701923
vtprotobuf+raw+unsafeunm6554413212.2692233
vtprotobuf+raw+unsafeunm+varint6402992218.7702233
vtprotobuf+raw6292698227.9692714
protobuf_mus+raw5407700231.8691272
protobuf_mus+raw+varint5300852243.2701272
vtprotobuf+raw+varint5882449246.4702714
protobuf+raw+varint2460066503.1702714
protobuf+raw2213274504.4692714
json42177726971506009
gob66589178801599407233

, where iterations count, ns/op, B/op, allocs/op are standard go test -bench=. output and B/size - determines how many bytes were used on average by the serializer to encode Data.

Features

List of Features

Each feature describes a serializer:

Features that must be in the result name when used:

This list can be expanded.

Data

Randomly generated data has the following form:

type Data struct {
  Str     string
  Bool    bool
  Int32   int32
  Float64 float64
  Time    time.Time
}

It does not have an int type because many serializers do not support it.

Run Benchmarks

From the benchmarks/ folder:

go test -bench=.

We can also filter the serializers by features, for example:

go test -bench=. -- -f binary,manual

In this case we will see the results of serializers that have both binary and manual features. To run benchmarks for one particular case just name it, for example:

go test -bench=BenchmarkSerializers/mus

or

go test -bench=/.+reuse

to see the results obtained using the reuse feature.

Generate README.md

From the benchmarks/ folder:

go generate ./...

Recomendation

When creating README.md on a laptop, please make sure that it is connected to a charger and the fan is running at full speed.

Contribution

First of all, you need to create a new package for your serializer if it doesn't already exist. Then:

  1. Implement serializer.Serializer[serializer.Data] interface. Doing this you can use:
  2. If you use own Data make shure it implements EqualTo(data Data) error method, also add func ToYourData(data serializer.Data) (d Data) function (an example can be found in bbebop200sc/serializers.go).
  3. Define
    var Serializers = []serializer.Serializer[serializer.Data]{Serializer{}}
    
    variable. Note that it can contain several serializers that produce different results.
  4. Create PR.

If you want to run benchmarks from your own project, there is the benchser.BenchmarkSerializer(...) function.