-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjson_marshal_benchmark_test.go
120 lines (108 loc) · 2.4 KB
/
json_marshal_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
package generic
import (
"net/url"
"testing"
"time"
)
func BenchmarkMarshalJSONBool(b *testing.B) {
x := Bool{
ValidFlag: true,
bool: true,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONFloat(b *testing.B) {
x := Float{
ValidFlag: true,
float: 1000.000001,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONInt(b *testing.B) {
x := Int{
ValidFlag: true,
int: 10000,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONString(b *testing.B) {
x := String{
ValidFlag: true,
string: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONStringLarge(b *testing.B) {
x := String{
ValidFlag: true,
string: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONTime(b *testing.B) {
x := Time{
ValidFlag: true,
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONTimestampMS(b *testing.B) {
x := TimestampMS{
ValidFlag: true,
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONTimestampNano(b *testing.B) {
x := TimestampNano{
ValidFlag: true,
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONTimestamp(b *testing.B) {
x := Timestamp{
ValidFlag: true,
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONUint(b *testing.B) {
x := Uint{
ValidFlag: true,
uint: 10000,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}
func BenchmarkMarshalJSONURL(b *testing.B) {
x := URL{
ValidFlag: true,
url: &url.URL{
Scheme: "https",
Host: "www.google.com",
},
}
for i := 0; i < b.N; i++ {
x.MarshalJSON() // nolint
}
}