Skip to content

Commit e99f90c

Browse files
committed
add benchmark
1 parent 5deded7 commit e99f90c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

bench_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package null
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func BenchmarkIntUnmarshalJSON(b *testing.B) {
8+
input := []byte("123456")
9+
var nullable Int
10+
for n := 0; n < b.N; n++ {
11+
nullable.UnmarshalJSON(input)
12+
}
13+
}
14+
15+
func BenchmarkIntStringUnmarshalJSON(b *testing.B) {
16+
input := []byte(`"123456"`)
17+
var nullable String
18+
for n := 0; n < b.N; n++ {
19+
nullable.UnmarshalJSON(input)
20+
}
21+
}
22+
23+
func BenchmarkNullIntUnmarshalJSON(b *testing.B) {
24+
input := []byte("null")
25+
var nullable Int
26+
for n := 0; n < b.N; n++ {
27+
nullable.UnmarshalJSON(input)
28+
}
29+
}
30+
31+
func BenchmarkStringUnmarshalJSON(b *testing.B) {
32+
input := []byte(`"hello"`)
33+
var nullable String
34+
for n := 0; n < b.N; n++ {
35+
nullable.UnmarshalJSON(input)
36+
}
37+
}
38+
39+
func BenchmarkNullStringUnmarshalJSON(b *testing.B) {
40+
input := []byte("null")
41+
var nullable String
42+
for n := 0; n < b.N; n++ {
43+
nullable.UnmarshalJSON(input)
44+
}
45+
}

0 commit comments

Comments
 (0)