...
1
16
17 package issue_test
18
19 import (
20 `fmt`
21 `time`
22 `testing`
23 `reflect`
24
25 `github.com/stretchr/testify/require`
26 `github.com/bytedance/sonic`
27 `github.com/bytedance/sonic/option`
28 )
29
30 type Issue138_DeepStruct struct {
31 L0 struct {
32 L1 struct {
33 L2 struct {
34 L3 struct {
35 L4 struct {
36 L5 struct {
37 L6 struct {
38 L7 struct {
39 L8 struct {
40 L9 struct {
41 L10 struct {
42 L11 struct {
43 L12 struct {
44 L13 struct {
45 L14 struct {
46 L15 struct {
47 L16 struct {
48 L17 struct {
49 L18 struct {
50 L19 struct {
51 L20 struct {
52 L21 struct {
53 L22 struct {
54 A int
55 B string
56 C []float64
57 E map[string]bool
58 F *Issue138_DeepStruct
59 }}}}}}}}}}}}}}}}}}}}}}}
60 }
61
62 func testPretouchTime(depth int) {
63 start := time.Now()
64 sonic.Pretouch(reflect.TypeOf(Issue138_DeepStruct{}), option.WithCompileRecursiveDepth(depth))
65 elapsed := time.Since(start)
66 fmt.Printf("Pretouch with recursive depth %d, time is %s\n", depth, elapsed)
67 }
68
69 func TestIssue138_PretouchTime(t *testing.T) {
70 testPretouchTime(4)
71 var obj Issue138_DeepStruct
72 start := time.Now()
73 data, err := sonic.Marshal(obj)
74 err = sonic.Unmarshal([]byte(data), &obj)
75 elapsed := time.Since(start)
76 fmt.Printf("Marshal and unmarshal time is %s\n", elapsed)
77 require.NoError(t, err)
78 }
79
80
View as plain text