-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark_test.go
75 lines (68 loc) · 976 Bytes
/
benchmark_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package dynamic
import (
"encoding/json"
"fmt"
"testing"
)
type x struct {
X string
}
type y struct {
Y int
}
func createX() interface{} {
return &x{}
}
func createY() interface{} {
return &y{}
}
func init() {
Register("x", createX)
Register("y", createY)
}
func BenchmarkUnmarshal(b *testing.B) {
data := []byte(`
{
"object": {
"type": "x",
"x": "x",
"foo": "bar"
},
"list": [
{
"type": "x",
"x": "0",
"foo": ["bar", "bas", "baz"]
},
{
"type": "y",
"y": 1,
"foo": {"bar": "bar", "baz": "baz"}
},
{
"type": "x",
"x": "0",
"y": 1,
"foo": [1, 2, 3, 4, 5]
},
{
"type": "y",
"x": "0",
"y": 1,
"foo": {"bar": ["b", "ba", "ar"]}
}
]
}
`)
var test struct {
Object Type
List []Type
}
for i := 0; i < b.N; i++ {
err := json.Unmarshal(data, &test)
if err != nil {
fmt.Printf("%v\n%#v\n", err, test)
break
}
}
}