-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark_test.go
119 lines (103 loc) · 2.39 KB
/
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
// +build all
package main
import (
"encoding/json"
"testing"
database "github.com/YaleOpenLab/openx/database"
"github.com/pquerna/ffjson/ffjson"
)
// go test -run=XXX -tags="all" -bench=.
// pit three json encoding libraries against each other to see which one is the fastest.
func BenchmarkFFJsonMarshal(b *testing.B) {
s := &database.User{
Index: 1,
Name: "testuser",
PublicKey: "randompublickey",
Username: "myusername",
Pwhash: "mypwhash",
Address: "myhomeaddress",
Description: "mydescription",
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = ffjson.Marshal(s)
}
}
func BenchmarkFFJsonUnmarshal(b *testing.B) {
s := &database.User{
Index: 1,
Name: "testuser",
PublicKey: "randompublickey",
Username: "myusername",
Pwhash: "mypwhash",
Address: "myhomeaddress",
Description: "mydescription",
}
data, _ := ffjson.Marshal(s)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ffjson.Unmarshal(data, &s)
}
}
func BenchmarkEJsonMarshal(b *testing.B) {
s := &database.User{
Index: 1,
Name: "testuser",
PublicKey: "randompublickey",
Username: "myusername",
Pwhash: "mypwhash",
Address: "myhomeaddress",
Description: "mydescription",
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = s.MarshalJSON()
}
}
func BenchmarkEJsonUnmarshal(b *testing.B) {
s := &database.User{
Index: 1,
Name: "testuser",
PublicKey: "randompublickey",
Username: "myusername",
Pwhash: "mypwhash",
Address: "myhomeaddress",
Description: "mydescription",
}
data, _ := s.MarshalJSON()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = s.UnmarshalJSON(data)
}
}
func BenchmarkJsonMarshal(b *testing.B) {
s := &database.User{
Index: 1,
Name: "testuser",
PublicKey: "randompublickey",
Username: "myusername",
Pwhash: "mypwhash",
Address: "myhomeaddress",
Description: "mydescription",
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = json.Marshal(&s)
}
}
func BenchmarkJsonUnmarshal(b *testing.B) {
s := &database.User{
Index: 1,
Name: "testuser",
PublicKey: "randompublickey",
Username: "myusername",
Pwhash: "mypwhash",
Address: "myhomeaddress",
Description: "mydescription",
}
data, _ := json.Marshal(s)
b.ResetTimer()
for i := 0; i < b.N; i++ {
json.Unmarshal(data, &s)
}
}