forked from mattbaird/jsonpatch
-
Notifications
You must be signed in to change notification settings - Fork 14
/
bench_test.go
56 lines (51 loc) · 862 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
package jsonpatch_test
import (
"encoding/json"
"testing"
"gomodules.xyz/jsonpatch/v2"
)
func BenchmarkCreatePatch(b *testing.B) {
cases := []struct {
name string
a, b string
}{
{
"complex",
superComplexBase,
superComplexA,
},
{
"large array",
largeArray(1000, "a"),
largeArray(1000, "b"),
},
{
"simple",
simpleA,
simpleB,
},
}
for _, tt := range cases {
b.Run(tt.name, func(b *testing.B) {
at := []byte(tt.a)
bt := []byte(tt.b)
for n := 0; n < b.N; n++ {
_, _ = jsonpatch.CreatePatch(at, bt)
}
})
}
}
func largeArray(size int, val string) string {
type nested struct {
A, B string
}
type example struct {
Objects []nested
}
a := example{}
for i := 0; i < size; i++ {
a.Objects = append(a.Objects, nested{A: "a", B: val})
}
res, _ := json.Marshal(a)
return string(res)
}