bnclabs / gson

Algorithms on data formats - JSON, CBOR, Collation.
http://prataprc.github.io/jsonsort.io
MIT License
19 stars 8 forks source link

Investigate Benchmarks #6

Open prataprc opened 7 years ago

prataprc commented 7 years ago

BenchmarkVal2CollMap 50000 26696 ns/op 16416 B/op 2 allocs/op BenchmarkVal2CollTyp 10000 174548 ns/op 49250 B/op 6 allocs/op

BenchmarkJson2CollStr 2000 635015 ns/op 1048647 B/op 5 allocs/op

BenchmarkCbor2CollMap 2000 787087 ns/op 1089654 B/op 8 allocs/op BenchmarkCbor2CollTyp 500 2500523 ns/op 3269067 B/op 25 allocs/op

prataprc commented 7 years ago

strconv.AppendFloat, and, strconv.AppendInt avoid heap allocations, lowering the memory pressure, hence suitable for tight loops. Except that, it does appen() on the input byte-slice hence the slice itself escapes to heap. So there is still 1 allocation that can't be avoided.

In case of CollateIint64 and CollateFloat64, there is an allocation for each call to AppendFloat/AppendInt.

Above benchmarks are on data that has integers and floats. So, we can't have a true ZERO allocation API to convert float to string and int to string.