-
Notifications
You must be signed in to change notification settings - Fork 12
/
pcopy_benchmark_interface_base_test.go
107 lines (96 loc) · 2.09 KB
/
pcopy_benchmark_interface_base_test.go
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
106
107
// Copyright [2020-2023] [guonaihong]
package pcopy
import (
"testing"
)
type interfaceBaseSrcTest 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 interfaceDstTest interfaceBaseSrcTest
var localInterfaceSrcTest = interfaceBaseSrcTest{
A: uint(1),
B: uint8(2),
C: uint16(3),
D: uint32(4),
E: uint64(5),
F: int(6),
G: int8(7),
H: int16(8),
I: int32(9),
J: int64(10),
K: float32(11),
L: float64(12),
M: "13",
N: true,
}
func Benchmark_Interface_Unsafe_Pcopy(b *testing.B) {
var dst interfaceDstTest
err := Preheat(&dst, &localInterfaceSrcTest)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var dst interfaceDstTest
err := Copy(&dst, &localInterfaceSrcTest, WithUsePreheat())
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Interface_RawCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst interfaceDstTest
dst.A = localInterfaceSrcTest.A.(uint)
dst.B = localInterfaceSrcTest.B.(uint8)
dst.C = localInterfaceSrcTest.C.(uint16)
dst.D = localInterfaceSrcTest.D.(uint32)
dst.E = localInterfaceSrcTest.E.(uint64)
dst.F = localInterfaceSrcTest.F.(int)
dst.G = localInterfaceSrcTest.G.(int8)
dst.H = localInterfaceSrcTest.H.(int16)
dst.I = localInterfaceSrcTest.I.(int32)
dst.J = localInterfaceSrcTest.J.(int64)
dst.K = localInterfaceSrcTest.K.(float32)
dst.L = localInterfaceSrcTest.L.(float64)
dst.M = localInterfaceSrcTest.M.(string)
dst.N = localInterfaceSrcTest.N.(bool)
a := &dst
b := a
_ = b
}
}
func Benchmark_Interface_MiniCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
// var dst testData
var dst interfaceDstTest
err := miniCopy(&dst, &localInterfaceSrcTest)
if err != nil {
b.Fatal(err)
}
// miniCopy(&dst, &td)
}
}
func Benchmark_Interface_Pcopy(b *testing.B) {
for i := 0; i < b.N; i++ {
// var dst testData
var dst interfaceDstTest
err := Copy(&dst, &localInterfaceSrcTest)
if err != nil {
b.Fatal(err)
}
}
}