Since I’ve decided to use
TOON instead of JSON, I’ve benchmarked the performance of serialization of 2 Go TOON libraries compared to JSON built-in serialization.
Here are the results using current version of the libraries and go 1.25:
% go run .
goos: darwin
goarch: arm64
pkg: bench_toon
cpu: Apple M3 Pro
BenchmarkJSONMarshalCompact-11 3488496 322.3 ns/op
BenchmarkJSONMarshal-11 767379 1546 ns/op
BenchmarkToonMarshal-11 669687 1782 ns/op
BenchmarkGotoonEncode-11 161412 7506 ns/op
PASS
ok bench_toon 5.143s
The libraries:
What we learned is:
- github.com/toon-format/toon-go is comparable to pretty-printed JSON, which is fair because TOON format is also pretty-printed (and can’t be compacted)
- github.com/alpkeskin/gotoon is significantly slower than github.com/toon-format/toon-go
- JSON compact is way faster than everything else
What it means to me is that speed of TOON serialization in Go is not deal breaker. Program would have to spend most of the time serializing for the speed difference to matter.