...
1
16
17 package issue_test
18
19 import (
20 `encoding/json`
21 `fmt`
22 `sync`
23 `testing`
24
25 `github.com/bytedance/sonic`
26 )
27
28 func TestGcWriteBarrier(t *testing.T) {
29
30 size := 10_0000
31 data := make([]int, size)
32 date, _ := json.Marshal(data)
33
34
35 wg := sync.WaitGroup{}
36
37 for i := 0; i < 1000; i++ {
38 wg.Add(1)
39 cd := make([]byte, len(date))
40 copy(cd, date)
41 go func() {
42 var w []int
43 defer wg.Done()
44
45 if err := sonic.Unmarshal(cd, &w); err != nil {
46 fmt.Println(err)
47 }
48 }()
49 }
50 wg.Wait()
51 }
52
53 func BenchmarkGcGuard(b *testing.B) {
54 size := 10_0000
55 data := make([]int, size)
56 date, _ := json.Marshal(data)
57 b.RunParallel(func(p *testing.PB) {
58 for p.Next() {
59 var w []int
60 _ = sonic.Unmarshal(date, &w)
61 }
62 })
63 }
View as plain text