-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
133 lines (109 loc) · 2.65 KB
/
main_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
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"encoding/json"
"testing"
sonic "github.com/bytedance/sonic"
goccy "github.com/goccy/go-json"
sonnet "github.com/sugawarayuuta/sonnet"
)
// var in Person = Person{"NAME", "31uEbMgunupShBVTewXjtqbBv5MndwfXhb", 1000}
var in string = `{ "name": "NAME", "address": "31uEbMgunupShBVTewXjtqbBv5MndwfXhb", "age": "1000" }`
func BenchmarkJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
jsonB := EncodeJSON(in)
DecodeJSON(jsonB)
}
}
func BenchmarkGoccyJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
jsonB := EncodeGoccyJSON(in)
DecodeGoccyJSON(jsonB)
}
}
func BenchmarkSonicJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
jsonB := EncodeSonicJSON(in)
DecodeSonicJSON(jsonB)
}
}
func BenchmarkSonnetJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
jsonB := EncodeSonnetJSON(in)
DecodeSonnetJSON(jsonB)
}
}
// func BenchmarkMsgPack(b *testing.B) {
// for i := 0; i < b.N; i++ {
// jsonB := EncodeMsgPack(in)
// DecodeMsgPack(jsonB)
// }
// }
// func BenchmarkMsgP(b *testing.B) {
// for i := 0; i < b.N; i++ {
// jsonB := EncodeMsgP(in)
// _ = DecodeMsgP(jsonB)
// }
// }
// func BenchmarkMsgPackGen(b *testing.B) {
// RegisterGeneratedResolver()
// for i := 0; i < b.N; i++ {
// jsonB := EncodeMsgPackgen(in)
// _ = DecodeMsgPackgen(jsonB)
// }
// }
func EncodeJSON(message string) (out []byte) {
out, _ = json.Marshal(message)
return out
}
func DecodeJSON(b []byte) (out Person) {
_ = json.Unmarshal(b, &out)
return
}
func EncodeGoccyJSON(message string) (out []byte) {
out, _ = goccy.Marshal(message)
return out
}
func DecodeGoccyJSON(b []byte) (out Person) {
_ = goccy.Unmarshal(b, &out)
return
}
func EncodeSonicJSON(message string) (out []byte) {
out, _ = sonic.Marshal(message)
return out
}
func DecodeSonicJSON(b []byte) (out Person) {
_ = sonic.Unmarshal(b, &out)
return
}
func EncodeSonnetJSON(message string) (out []byte) {
out, _ = sonnet.Marshal(message)
return out
}
func DecodeSonnetJSON(b []byte) (out Person) {
_ = sonnet.Unmarshal(b, &out)
return
}
// func EncodeMsgPack(message Person) (out []byte) {
// out, _ = msgpack.Marshal(message)
// return out
// }
// func DecodeMsgPack(b []byte) (out Person) {
// _ = msgpack.Unmarshal(b, &out)
// return out
// }
// func EncodeMsgP(message Person) (out []byte) {
// out, _ = message.MarshalMsg(nil)
// return out
// }
// func DecodeMsgP(data []byte) (out Person) {
// _, _ = out.UnmarshalMsg(data)
// return
// }
// func EncodeMsgPackgen(message Person) (out []byte) {
// out, _ = msgpackgen.Marshal(message)
// return out
// }
// func DecodeMsgPackgen(data []byte) (out Person) {
// _ = msgpackgen.Unmarshal(data, &out)
// return
// }