-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patheasyjson_test.go
70 lines (54 loc) · 1.49 KB
/
easyjson_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
package json
import (
"strconv"
"testing"
"github.com/mailru/easyjson"
)
func BenchmarkEasyjsonUnmarshal(b *testing.B) {
b.Run(strconv.Itoa(len(smallStructText)), func(b *testing.B) { benchmarkEasyjsonUnmarshalSmallData(b) })
b.Run(strconv.Itoa(len(largeStructText)), func(b *testing.B) { benchmarkEasyjsonUnmarshalLargeData(b) })
}
func benchmarkEasyjsonUnmarshalLargeData(b *testing.B) {
b.SetBytes(int64(len(largeStructText)))
for i := 0; i < b.N; i++ {
var s LargeStruct
if err := s.UnmarshalJSON(largeStructText); err != nil {
b.Error(err)
}
}
}
func benchmarkEasyjsonUnmarshalSmallData(b *testing.B) {
b.SetBytes(int64(len(smallStructText)))
for i := 0; i < b.N; i++ {
var s Entities
if err := s.UnmarshalJSON(smallStructText); err != nil {
b.Error(err)
}
}
}
func BenchmarkEasyjsonMarshal(b *testing.B) {
b.Run(strconv.Itoa(len(smallStructText)), func(b *testing.B) { benchmarkEasyjsonMarshalSmallData(b) })
b.Run(strconv.Itoa(len(largeStructText)), func(b *testing.B) { benchmarkEasyjsonMarshalLargeData(b) })
}
func benchmarkEasyjsonMarshalLargeData(b *testing.B) {
var l int64
for i := 0; i < b.N; i++ {
data, err := easyjson.Marshal(&largeStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
b.SetBytes(l)
}
func benchmarkEasyjsonMarshalSmallData(b *testing.B) {
var l int64
for i := 0; i < b.N; i++ {
data, err := easyjson.Marshal(&smallStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
b.SetBytes(l)
}