go-json-benchmark

command module
v0.0.0-...-5c22601 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2019 License: MIT Imports: 1 Imported by: 0

README

Build Status

go-json-benchmark

Benchmark suite for JSON parsing and serialization.

Libraries

Library Notes
encoding/json (aka 'std') Testing Marshal/Unmarshal rather than Decode/Encode since this benchmark suite assumes JSON exists in memory and not incoming from a stream
easyjson Generates parser methods structs defined in <data_file>.go. Testing MarshalJSON/UnmarshalJSON.
ffjson Generates parser methods structs defined in <data_file>.go. Testing MarshalFast/UnmarshalFast
jsoniter Testing Marshal/Unmarshal.
jingo Testing Marshal (no Unmarshal). Requires initializing an encoder per struct/slice that should be marshaled. Currently does not marshal maps.

Benchmarks

Performance
Benchmark Description
Marshal Encode JSON data from a Go type or struct
Unmarshal Decode JSON data from memory into to a Go type or struct

Each benchmark should be tested against each dataset. Generic benchmark helpers are defined in benchmark.go.

Datasets
JSON file Size Description
small.json source 1KB
large.json source 1687KB A big benchmark file with indentation used in several Java JSON parser benchmarks.
canada.json source 2199KB Contour of Canada border in GeoJSON format. Contains a lot of real numbers.

These datasets were pulled from nativejson-benchmark. Data structs are defined in data.go.

Results

Results of Marshal benchmarking:

Rank Library Performance
1 jingo 326 ns/op
2 ffjson 327 ns/op
3 easyjson 12379009 ns/op
4 standardjson 26374413 ns/op
5 jsoniter 26768552 ns/op

Results of Unmarshal benchmarking:

Rank Library Performance
1 easyjson 20851164 ns/op
2 ffjson 21516266 ns/op
3 jsoniter 27719141 ns/op
4 standardjson 39032163 ns/op

The average across all datasets is calculated for each performance metric.

Adding new libraries for benchmarking

  • create LIBNAME_test.go
  • create each benchmark * each dataset - use the base benchmark helpers in benchmark.go if applicable

TODO

  • makefile
  • CI/CD
  • data presentation
  • benchmark for libs that support field querying rather than converting to/from predefined struct

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
rank
Tool to generate benchmark ranks and output back to README using templating
Tool to generate benchmark ranks and output back to README using templating

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL