-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathdecoder_bench_large_test.go
59 lines (51 loc) · 1.52 KB
/
decoder_bench_large_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package benchmarks
import (
"testing"
"github.com/buger/jsonparser"
"github.com/francoispqt/gojay"
"github.com/francoispqt/gojay/benchmarks"
jsoniter "github.com/json-iterator/go"
"github.com/mailru/easyjson"
)
func BenchmarkJsonParserDecodeObjLarge(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
jsonparser.ArrayEach(benchmarks.LargeFixture, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
jsonparser.Get(value, "username")
nothing()
}, "users")
jsonparser.ArrayEach(benchmarks.LargeFixture, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
jsonparser.GetInt(value, "id")
jsonparser.Get(value, "slug")
nothing()
}, "topics", "topics")
}
}
func BenchmarkJsonIterDecodeObjLarge(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := benchmarks.LargePayload{}
jsoniter.Unmarshal(benchmarks.LargeFixture, &result)
}
}
func BenchmarkEasyJsonDecodeObjLarge(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := benchmarks.LargePayload{}
easyjson.Unmarshal(benchmarks.LargeFixture, &result)
}
}
func BenchmarkGoJayDecodeObjLarge(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := benchmarks.LargePayload{}
gojay.UnmarshalJSONObject(benchmarks.LargeFixture, &result)
}
}
func BenchmarkGoJayUnsafeDecodeObjLarge(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := benchmarks.LargePayload{}
gojay.Unsafe.UnmarshalJSONObject(benchmarks.LargeFixture, &result)
}
}