-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpcopy_benchmark_slice_with_struct_test.go
54 lines (45 loc) · 1.2 KB
/
pcopy_benchmark_slice_with_struct_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
// Copyright [2020-2023] [guonaihong]
package pcopy
import "testing"
func Benchmark_SliceWithStruct_Unsafe_Pcopy(b *testing.B) {
var dst test_SliceWithStruct_Src
err := Preheat(&dst, &test_SliceWithStruct_Src{})
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var dst test_SliceWithStruct_Src
// err := Copy(&dst, &local_SliceWithStruct_Src)
err := Copy(&dst, &local_SliceWithStruct_Src, WithUsePreheat())
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_SliceWithStruct_RawCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst test_SliceWithStruct_Dst
dst.A = make([]test_SliceWithStruct_Dst_Item1, len(local_SliceWithStruct_Src.A))
copy(dst.A, local_SliceWithStruct_Src.A)
dst.B = append(dst.B, local_SliceWithStruct_Src.B...)
}
}
func Benchmark_SliceWithStruct_miniCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst test_SliceWithStruct_Src
err := miniCopy(&dst, &local_SliceWithStruct_Src)
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_SliceWithStruct_Reflect_Pcopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst test_SliceWithStruct_Src
err := Copy(&dst, &local_SliceWithStruct_Src)
if err != nil {
b.Fatal(err)
}
}
}