-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbench_test.go
59 lines (50 loc) · 947 Bytes
/
bench_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
//go:build !gofuzz && go1.17
// +build !gofuzz,go1.17
package jx
import (
_ "embed"
"encoding/json"
"testing"
)
//go:embed testdata/file.json
var data []byte
func Benchmark_large_file(b *testing.B) {
b.ReportAllocs()
d := Decode(nil, 4096)
for n := 0; n < b.N; n++ {
d.ResetBytes(data)
if err := d.Arr(nil); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkValid(b *testing.B) {
b.Run("JX", func(b *testing.B) {
b.ReportAllocs()
b.SetBytes(int64(len(data)))
for n := 0; n < b.N; n++ {
if !Valid(data) {
b.Fatal("invalid")
}
}
})
b.Run("Std", func(b *testing.B) {
b.ReportAllocs()
b.SetBytes(int64(len(data)))
for n := 0; n < b.N; n++ {
if !json.Valid(data) {
b.Fatal("invalid")
}
}
})
}
func Benchmark_std_large_file(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
var result []struct{}
err := json.Unmarshal(data, &result)
if err != nil {
b.Error(err)
}
}
}