You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-07-06 23:37:39 +02:00
Unmarshalling float with lots of digits can cause >= 2 allocations per number
We can fix this with a little bit of scratch space.
This commit is contained in:
28
benchmarks/float_test.go
Normal file
28
benchmarks/float_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func BenchmarkFloatUnmarshal(b *testing.B) {
|
||||
type floaty struct {
|
||||
A float32
|
||||
B float64
|
||||
}
|
||||
|
||||
data, err := jsoniter.Marshal(floaty{A: 1.111111111111111, B: 1.11111111111111})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
var out floaty
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := jsoniter.Unmarshal(data, &out); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user