-
Notifications
You must be signed in to change notification settings - Fork 7
/
json_unmarshal_benchmark_test.go
148 lines (117 loc) · 3.43 KB
/
json_unmarshal_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package generic
import (
"testing"
"time"
)
func BenchmarkUnmarshalJSONBoolFromBool(b *testing.B) {
unmarshalJSONBoolBenchmark(b, []byte(`true`))
}
func BenchmarkUnmarshalJSONBoolFromFloat(b *testing.B) {
unmarshalJSONBoolBenchmark(b, []byte(`1.0`))
}
func BenchmarkUnmarshalJSONBoolFromInt(b *testing.B) {
unmarshalJSONBoolBenchmark(b, []byte(`1`))
}
func BenchmarkUnmarshalJSONBoolFromString(b *testing.B) {
unmarshalJSONBoolBenchmark(b, []byte(`"true"`))
}
func BenchmarkUnmarshalJSONIntFromBool(b *testing.B) {
unmarshalJSONIntBenchmark(b, []byte(`true`))
}
func BenchmarkUnmarshalJSONIntFromFloat(b *testing.B) {
unmarshalJSONIntBenchmark(b, []byte(`1.0`))
}
func BenchmarkUnmarshalJSONIntFromInt(b *testing.B) {
unmarshalJSONIntBenchmark(b, []byte(`1`))
}
func BenchmarkUnmarshalJSONIntFromString(b *testing.B) {
unmarshalJSONIntBenchmark(b, []byte(`"1.0"`))
}
func BenchmarkUnmarshalJSONUintFromBool(b *testing.B) {
unmarshalJSONUintBenchmark(b, []byte(`true`))
}
func BenchmarkUnmarshalJSONUintFromFloat(b *testing.B) {
unmarshalJSONUintBenchmark(b, []byte(`1.0`))
}
func BenchmarkUnmarshalJSONUintFromInt(b *testing.B) {
unmarshalJSONUintBenchmark(b, []byte(`1`))
}
func BenchmarkUnmarshalJSONUintFromString(b *testing.B) {
unmarshalJSONUintBenchmark(b, []byte(`"1.0"`))
}
func BenchmarkUnmarshalJSONFloatFromBool(b *testing.B) {
unmarshalJSONFloatBenchmark(b, []byte(`true`))
}
func BenchmarkUnmarshalJSONFloatFromFloat(b *testing.B) {
unmarshalJSONFloatBenchmark(b, []byte(`1.0`))
}
func BenchmarkUnmarshalJSONFloatFromInt(b *testing.B) {
unmarshalJSONFloatBenchmark(b, []byte(`1`))
}
func BenchmarkUnmarshalJSONFloatFromString(b *testing.B) {
unmarshalJSONFloatBenchmark(b, []byte(`"1.0"`))
}
func BenchmarkUnmarshalJSONFloatFromUint(b *testing.B) {
unmarshalJSONFloatBenchmark(b, []byte(`1`))
}
func BenchmarkUnmarshalJSONStringFromBool(b *testing.B) {
unmarshalJSONStringBenchmark(b, []byte(`true`))
}
func BenchmarkUnmarshalJSONStringFromFloat(b *testing.B) {
unmarshalJSONStringBenchmark(b, []byte(`1.0`))
}
func BenchmarkUnmarshalJSONStringFromInt(b *testing.B) {
unmarshalJSONStringBenchmark(b, []byte(`1`))
}
func BenchmarkUnmarshalJSONStringFromString(b *testing.B) {
unmarshalJSONStringBenchmark(b, []byte(`"true"`))
}
func BenchmarkUnmarshalJSONTimeFromString(b *testing.B) {
now := time.Now()
unmarshalJSONTimeBenchmark(b, []byte(`"`+now.String()+`"`))
}
func BenchmarkUnmarshalJSONURLFromString(b *testing.B) {
unmarshalJSONURLBenchmark(b, []byte(`"https://google.com"`))
}
func unmarshalJSONBoolBenchmark(b *testing.B, bs []byte) {
x := Bool{}
for i := 0; i < b.N; i++ {
x.UnmarshalJSON(bs) // nolint
}
}
func unmarshalJSONFloatBenchmark(b *testing.B, bs []byte) {
x := Float{}
for i := 0; i < b.N; i++ {
x.UnmarshalJSON(bs) // nolint
}
}
func unmarshalJSONIntBenchmark(b *testing.B, bs []byte) {
x := Int{}
for i := 0; i < b.N; i++ {
x.UnmarshalJSON(bs) // nolint
}
}
func unmarshalJSONStringBenchmark(b *testing.B, bs []byte) {
x := String{}
for i := 0; i < b.N; i++ {
x.UnmarshalJSON(bs) // nolint
}
}
func unmarshalJSONTimeBenchmark(b *testing.B, bs []byte) {
t := Time{}
for i := 0; i < b.N; i++ {
t.UnmarshalJSON(bs) // nolint
}
}
func unmarshalJSONUintBenchmark(b *testing.B, bs []byte) {
x := Uint{}
for i := 0; i < b.N; i++ {
x.UnmarshalJSON(bs) // nolint
}
}
func unmarshalJSONURLBenchmark(b *testing.B, bs []byte) {
x := URL{}
for i := 0; i < b.N; i++ {
x.UnmarshalJSON(bs) // nolint
}
}