-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpcopy_benchmark_interface_slice_test.go
More file actions
105 lines (94 loc) · 2.82 KB
/
Copy pathpcopy_benchmark_interface_slice_test.go
File metadata and controls
105 lines (94 loc) · 2.82 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright [2020-2023] [guonaihong]
package pcopy
import "testing"
type interfaceBaseSliceSrcTest struct {
A interface{}
B interface{}
C interface{}
D interface{}
E interface{}
F interface{}
G interface{}
H interface{}
I interface{}
J interface{}
K interface{}
L interface{}
M interface{}
N interface{}
}
type interfaceSliceDstTest interfaceBaseSliceSrcTest
var localInterfaceSliceSrcTest = interfaceBaseSliceSrcTest{
A: []int{1, 2, 3, 4, 5},
B: []int8{1, 2, 3, 4, 5},
C: []int16{1, 2, 3, 4, 5},
D: []int32{1, 2, 3, 4, 5},
E: []int64{1, 2, 3, 4, 5},
F: []uint{1, 2, 3, 4, 5},
G: []uint8{1, 2, 3, 4, 5},
H: []uint16{1, 2, 3, 4, 5},
I: []uint32{1, 2, 3, 4, 5},
J: []uint64{1, 2, 3, 4, 5},
K: []float32{1, 2, 3, 4, 5},
L: []float64{1, 2, 3, 4, 5},
M: []string{"1", "2", "3", "4", "5"},
N: []bool{true, false, true, false, true},
}
func Benchmark_Interface_BaseSlice_Unsafe_Pcopy(b *testing.B) {
var dst interfaceSliceDstTest
err := Preheat(&dst, &localInterfaceSliceSrcTest)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var dst interfaceSliceDstTest
err := Copy(&dst, &localInterfaceSliceSrcTest, WithUsePreheat())
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Interface_BaseSlice_RawCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst interfaceSliceDstTest
dst.A = append([]int{}, localInterfaceSliceSrcTest.A.([]int)...)
dst.B = append([]int8{}, localInterfaceSliceSrcTest.B.([]int8)...)
dst.C = append([]int16{}, localInterfaceSliceSrcTest.C.([]int16)...)
dst.D = append([]int32{}, localInterfaceSliceSrcTest.D.([]int32)...)
dst.E = append([]int64{}, localInterfaceSliceSrcTest.E.([]int64)...)
dst.F = append([]uint{}, localInterfaceSliceSrcTest.F.([]uint)...)
dst.G = append([]uint8{}, localInterfaceSliceSrcTest.G.([]uint8)...)
dst.H = append([]uint16{}, localInterfaceSliceSrcTest.H.([]uint16)...)
dst.I = append([]uint32{}, localInterfaceSliceSrcTest.I.([]uint32)...)
dst.J = append([]uint64{}, localInterfaceSliceSrcTest.J.([]uint64)...)
dst.K = append([]float32{}, localInterfaceSliceSrcTest.K.([]float32)...)
dst.L = append([]float64{}, localInterfaceSliceSrcTest.L.([]float64)...)
dst.M = append([]string{}, localInterfaceSliceSrcTest.M.([]string)...)
dst.N = append([]bool{}, localInterfaceSliceSrcTest.N.([]bool)...)
a := &dst
b := a
_ = b
}
}
func Benchmark_Interface_BaseSlice_MiniCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
// var dst testData
var dst interfaceSliceDstTest
err := miniCopy(&dst, &localInterfaceSliceSrcTest)
if err != nil {
b.Fatal(err)
}
// miniCopy(&dst, &td)
}
}
func Benchmark_Interface_BaseSlice_Pcopy(b *testing.B) {
for i := 0; i < b.N; i++ {
// var dst testData
var dst interfaceSliceDstTest
err := Copy(&dst, &localInterfaceSliceSrcTest)
if err != nil {
b.Fatal(err)
}
}
}