-
Notifications
You must be signed in to change notification settings - Fork 12
/
pcopy_benchmark_composite_map_test.go
68 lines (56 loc) · 1.3 KB
/
pcopy_benchmark_composite_map_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
// Copyright [2020-2023] [guonaihong]
package pcopy
import "testing"
func Benchmark_CompositeMap_Unsafe_Pcopy(b *testing.B) {
var dst test_MapWithMap_Dst
err := Preheat(&dst, &local_MapWithMap_Src)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var dst test_MapWithMap_Dst
err := Copy(&dst, &local_MapWithMap_Src, WithUsePreheat())
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_CompositeMap_RawCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst test_MapWithMap_Dst
dst.A = make(map[string]string)
for k, v := range local_MapWithMap_Src.A {
dst.A[k] = v
}
dst.B = make(map[string]map[string]string)
for k, v := range local_MapWithMap_Src.B {
dst.B[k] = make(map[string]string)
for k1, v1 := range v {
dst.B[k][k1] = v1
}
}
dst.C = make(map[string]test_MapWithMap_Item)
for k, v := range local_MapWithMap_Src.C {
dst.C[k] = v
}
}
}
func Benchmark_CompositeMap_miniCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst test_MapWithMap_Dst
err := miniCopy(&dst, &local_MapWithMap_Src)
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_CompositeMap_Reflect(b *testing.B) {
for i := 0; i < b.N; i++ {
var dst test_MapWithMap_Dst
err := Copy(&dst, &local_MapWithMap_Src)
if err != nil {
b.Fatal(err)
}
}
}