...
1
16
17 package issue_test
18
19 import (
20 . `github.com/bytedance/sonic`
21 `encoding/json`
22 `reflect`
23 `testing`
24
25 `github.com/stretchr/testify/assert`
26 )
27
28 func TestIssue3_Encode(t *testing.T) {
29 var v HugeStruct6
30 ret, err := Marshal(v)
31 assert.Nil(t, err)
32 assert.Equal(t, []byte(`{}`), ret)
33 }
34
35 func TestIssue3_Decode(t *testing.T) {
36 var v HugeStruct6
37 err := Unmarshal([]byte(`{}`), &v)
38 assert.Nil(t, err)
39 assert.Equal(t, HugeStruct6{}, v)
40 }
41
42 func BenchmarkIssue3_Encode_Sonic(b *testing.B) {
43 var v HugeStruct6
44 err := Pretouch(reflect.TypeOf(v))
45 assert.Nil(b, err)
46 b.ResetTimer()
47 for i := 0; i < b.N; i++ {
48 _, _ = Marshal(v)
49 }
50 }
51
52 func BenchmarkIssue3_Encode_StdLib(b *testing.B) {
53 var v HugeStruct6
54 ret, err := json.Marshal(v)
55 assert.Nil(b, err)
56 assert.Equal(b, []byte(`{}`), ret)
57 b.ResetTimer()
58 for i := 0; i < b.N; i++ {
59 _, _ = json.Marshal(v)
60 }
61 }
62
63 func BenchmarkIssue3_Decode_Sonic(b *testing.B) {
64 var v HugeStruct6
65 buf := []byte(`{}`)
66 err := Pretouch(reflect.TypeOf(v))
67 assert.Nil(b, err)
68 b.ResetTimer()
69 for i := 0; i < b.N; i++ {
70 _ = Unmarshal(buf, &v)
71 }
72 }
73
74 func BenchmarkIssue3_Decode_StdLib(b *testing.B) {
75 var v HugeStruct6
76 buf := []byte(`{}`)
77 err := json.Unmarshal(buf, &v)
78 assert.Nil(b, err)
79 assert.Equal(b, HugeStruct6{}, v)
80 b.ResetTimer()
81 for i := 0; i < b.N; i++ {
82 _ = json.Unmarshal(buf, &v)
83 }
84 }
85
View as plain text