forked from cnf/structhash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructhash_benchmark_test.go
95 lines (74 loc) · 1.48 KB
/
structhash_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
package structhash
import (
"encoding/json"
"testing"
)
type BenchData struct {
Bool bool
String string
Int int
Uint uint
Map map[string]*BenchData
Slice []*BenchData
Struct *BenchData
}
type BenchTags struct {
Bool bool `json:"f1" hash:"name:f1"`
String string `json:"f2" hash:"name:f2"`
Int int `json:"f3" hash:"name:f3"`
Uint uint `json:"f4" hash:"name:f4"`
}
func benchDataSimple() *BenchData {
return &BenchData{true, "simple", -123, 321, nil, nil, nil}
}
func benchDataFull() *BenchData {
foo := benchDataSimple()
bar := benchDataSimple()
m := make(map[string]*BenchData)
m["foo"] = foo
m["bar"] = bar
s := []*BenchData{
foo,
bar,
}
return &BenchData{true, "hello", -123, 321, m, s, foo}
}
func benchDataTags() *BenchTags {
return &BenchTags{true, "tags", -123, 321}
}
func BenchmarkSimpleJSON(b *testing.B) {
s := benchDataSimple()
for i := 0; i < b.N; i++ {
json.Marshal(s)
}
}
func BenchmarkSimpleDump(b *testing.B) {
s := benchDataSimple()
for i := 0; i < b.N; i++ {
Dump(s, 1)
}
}
func BenchmarkFullJSON(b *testing.B) {
s := benchDataFull()
for i := 0; i < b.N; i++ {
json.Marshal(s)
}
}
func BenchmarkFullDump(b *testing.B) {
s := benchDataFull()
for i := 0; i < b.N; i++ {
Dump(s, 1)
}
}
func BenchmarkTagsJSON(b *testing.B) {
s := benchDataTags()
for i := 0; i < b.N; i++ {
json.Marshal(s)
}
}
func BenchmarkTagsDump(b *testing.B) {
s := benchDataTags()
for i := 0; i < b.N; i++ {
Dump(s, 1)
}
}