-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson_test.go
More file actions
39 lines (34 loc) · 885 Bytes
/
json_test.go
File metadata and controls
39 lines (34 loc) · 885 Bytes
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
package libjson
import (
"encoding/json"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
const amount = 50_000
func BenchmarkLibJson(b *testing.B) {
data := strings.Repeat(`{"key1": "value","array": [],"obj": {},"atomArray": [11201,1e112,true,false,null,"str"]},`, amount)
d := []byte("[" + data[:len(data)-1] + "]")
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := New(d)
assert.NoError(b, err)
}
b.ReportAllocs()
}
func BenchmarkEncodingJson(b *testing.B) {
data := strings.Repeat(`{"key1": "value","array": [],"obj": {},"atomArray": [11201,1e112,true,false,null,"str"]},`, amount)
d := []byte("[" + data[:len(data)-1] + "]")
b.ResetTimer()
for i := 0; i < b.N; i++ {
v := []struct {
Key1 string
Array []any
Obj any
AtomArray []any
}{}
err := json.Unmarshal(d, &v)
assert.NoError(b, err)
}
b.ReportAllocs()
}