-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstruct_test.go
More file actions
63 lines (53 loc) · 1.67 KB
/
struct_test.go
File metadata and controls
63 lines (53 loc) · 1.67 KB
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
package deepcopy
import (
"testing"
"github.com/bytedance/sonic"
"github.com/mohae/deepcopy"
"github.com/stretchr/testify/assert"
)
type ST struct {
A int
B ST2
X int
Y string
Z []string
}
type ST2 struct {
C int
D []int
E string
}
func TestStructCopy(t *testing.T) {
a := ST{5, ST2{2, []int{1, 2, 3, 4, 5, 6, 7}, "iiiiiiiiiiiiiiiiiiiii"}, 1000000, "RRRRRRRRRR", []string{"x", "z", "b", "c", "b", "c", "a", "b", "c"}}
b := ST{}
DeepCopy(&a, &b)
assert.Equal(t, a, b)
}
func BenchmarkRawStructCopy(b *testing.B) {
_ = ST{5, ST2{2, []int{1, 2, 3, 4, 5, 6, 7}, "iiiiiiiiiii iiiiiiiiii"}, 1000000, "RRRRRRRRRR", []string{"x", "z", "b", "c", "b", "c", "a", "b", "c"}}
for i := 0; i < b.N; i++ {
a := ST{5, ST2{2, []int{1, 2, 3, 4, 5, 6, 7}, "iiiiiiiiiiiiiiiiiiiii"}, 1000000, "RRRRRRRRRR", []string{"x", "z", "b", "c", "b", "c", "a", "b", "c"}}
_ = a
}
}
func BenchmarkStructCopy(b *testing.B) {
a := ST{5, ST2{2, []int{1, 2, 3, 4, 5, 6, 7}, "iiiiiiiiiiiiiiiiiiiii"}, 1000000, "RRRRRRRRRR", []string{"x", "z", "b", "c", "b", "c", "a", "b", "c"}}
for i := 0; i < b.N; i++ {
b := ST{}
DeepCopy(&a, &b)
}
}
func BenchmarkMohaeStructCopy(b *testing.B) {
a := ST{5, ST2{2, []int{1, 2, 3, 4, 5, 6, 7}, "iiiiiiiiiiiiiiiiiiiii"}, 1000000, "RRRRRRRRRR", []string{"x", "z", "b", "c", "b", "c", "a", "b", "c"}}
for i := 0; i < b.N; i++ {
_, _ = deepcopy.Copy(a).([]string)
}
}
func BenchmarkSonicStructCopy(b *testing.B) {
a := ST{5, ST2{2, []int{1, 2, 3, 4, 5, 6, 7}, "iiiiiiiiiiiiiiiiiiiii"}, 1000000, "RRRRRRRRRR", []string{"x", "z", "b", "c", "b", "c", "a", "b", "c"}}
for i := 0; i < b.N; i++ {
bb, _ := sonic.Marshal(a)
y := ST{}
_ = sonic.Unmarshal(bb, &y)
}
}