-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunmarshal_structwithtag.go
49 lines (46 loc) · 1.26 KB
/
unmarshal_structwithtag.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
package json_benchmark
import (
"encoding/json"
"testing"
jsoniter "github.com/json-iterator/go"
ugorji "github.com/ugorji/go/codec"
"github.com/zerosnake0/jzon"
)
func Test_Unmarshal_StructWithTag(t *testing.T, f func(t *testing.T, cb func(data []byte, o interface{}) error)) {
t.Run(pkgJson, func(t *testing.T) {
f(t, func(data []byte, o interface{}) error {
return json.Unmarshal(data, o)
})
})
t.Run(pkgJsoniter, func(t *testing.T) {
f(t, func(data []byte, o interface{}) error {
return jsoniter.Unmarshal(data, o)
})
})
t.Run(pkgJsoniterCompatible, func(t *testing.T) {
f(t, func(data []byte, o interface{}) error {
return jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, o)
})
})
t.Run(pkgUgorji, func(t *testing.T) {
f(t, func(data []byte, o interface{}) error {
h := ugorji.JsonHandle{
PreferFloat: true,
MapKeyAsString: true,
}
h.ErrorIfNoField = true
dec := ugorji.NewDecoderBytes(data, &h)
return dec.Decode(o)
})
})
t.Run(pkgJzon, func(t *testing.T) {
f(t, func(data []byte, o interface{}) error {
return jzon.Unmarshal(data, o)
})
})
t.Run(pkgJzonFast, func(t *testing.T) {
f(t, func(data []byte, o interface{}) error {
return jzonFastDecoderConfig.Unmarshal(data, o)
})
})
}