Categorygithub.com/alecthomas/go_serialization_benchmarks
modulepackage
0.0.0-20240830213112-630ee59b8e56
Repository: https://github.com/alecthomas/go_serialization_benchmarks.git
Documentation: pkg.go.dev

# README

Benchmarks of Go serialization methods

Gitter chat

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

Current Serialization Results

https://alecthomas.github.io/go_serialization_benchmarks

Running the benchmarks

To benchmark and validate, without cloning the repository, replace the . from the commands below with github.com/alecthomas/go_serialization_benchmarks@latest.

go run .

To validate the correctness of the serializers:

go run . --validate

To update the benchmark report:

go run . --genreport

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

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

Recommendation

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 run . --genreport
  • Include the updated report data in your PR

Data

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
}

# Packages

No description provided by the author

# Functions

No description provided by the author

# Constants

AKCodegen means there's a code generation step that is used to generate the client code used for marshalling/unmarshalling.
AKManual means the user must manually write the code to marshal/unmarshal structures.
AKReflect means the serializer uses Go's reflect API to marshal/ unmarshal objects.
TSCustom means the serializer has custom restrictions on time.Time fields.
TSFullRange means the serializer supports the full time.Time range, but without timezone information.
TSFullTzOffset means the serializer supports the full time.Time range, including timezone offset information (but not timezone names).
TSNoSupport means the serializer does not natively encode time.Time fields.
TSRFC3339Ns means the serializer supports encoding time values by using RFC3339 strings with nanosecond precision.
TSUnixMs means the serializer supports time by encoding into an int64 milliseconds since unix.
TSUnixNs means the serializer supports time by encoding into an int64 nanoseconds since unix.
TSUnknown means the serializer has not documented the encoding or the limitations on encoding time.Time values.

# Structs

No description provided by the author

# Type aliases

APIKind is the type of API needed to interact with the serializer.
TimeSupport is the type of support for time.Time values.