Go Serialization Benchmarks Save

Benchmarks of Go serialization methods

Project README

Benchmarks of Go serialization methods

Gitter chat

This is a test suite for benchmarking various Go serialization methods.

Current Serialization Results


Running the benchmarks

go test -bench=.

To validate the correctness of the serializers:

VALIDATE=1 go test -bench=. -benchtime=1ms

To update the benchmark report:

go test -tags genreport -run TestGenerateReport

To update the benchmark report with using a longer run benchmark (to get more accurate results):

go test -tags genreport -run TestGenerateReport -benchtime 10s -timeout 1h


If correctness and interoperability are the most important factors JSON or Protobuf are your best options.

But as always, make your own choice based on your requirements.

Adding New Serializers

Review the following instructions before opening the PR to add a new serializer:

  • Create all the required serializer code in internal/<short serializer name>.
  • Add an entry to the serializer in benchmarks.go.
  • If the serializer supports both reusing/not reusing its marshalling buffer:
    • Add both a serializer and serializer/reuse entries, each one respectively reusing/not reusing the resulting marshalling buffer. Set the BufferReuseMarshal flag accordingly.
  • If the serializer supports both safe and unsafe string unmarshalling:
    • Add both a serializer and serializer/unsafe entries, each one respectively unmarshalling into safe and unsafe strings. Set the UnsafeStringUnmarshal flag accordingly.
  • If the serializer supports both marshalling buffer reuse and unsafe string unmarshalling, merge both options into a single serializer/unsafe_reuse entry (check the baseline serializer for an example).
  • Regenerate the report by running:
go test -tags genreport -run TestGenerateReport
  • Include the updated report data in your PR


The data being serialized is the following structure with randomly generated values:

type A struct {
    Name     string
    BirthDay time.Time
    Phone    string
    Siblings int
    Spouse   bool
    Money    float64
Open Source Agenda is not affiliated with "Go Serialization Benchmarks" Project. README Source: alecthomas/go_serialization_benchmarks
Open Issues
Last Commit
5 days ago

Open Source Agenda Badge

Open Source Agenda Rating