-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbench_test.go
More file actions
65 lines (57 loc) · 1.24 KB
/
Copy pathbench_test.go
File metadata and controls
65 lines (57 loc) · 1.24 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
// Copyright 2022 The golang.design Initiative Authors.
// All rights reserved. Use of this source code is governed
// by a MIT license that can be found in the LICENSE file.
package reflect
import "testing"
type benchNode struct {
ID int
Name string
Weights []float64
Children []*benchNode
}
func newBenchTree(depth, fanout int) *benchNode {
n := &benchNode{
ID: depth,
Name: "node",
Weights: []float64{1, 2, 3, 4},
}
if depth <= 0 {
return n
}
for i := 0; i < fanout; i++ {
n.Children = append(n.Children, newBenchTree(depth-1, fanout))
}
return n
}
func BenchmarkDeepCopyPrimitive(b *testing.B) {
src := 42
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = DeepCopy(src)
}
}
func BenchmarkDeepCopySlice(b *testing.B) {
src := make([]int, 1024)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = DeepCopy(src)
}
}
func BenchmarkDeepCopyMap(b *testing.B) {
src := make(map[int]string, 256)
for i := 0; i < 256; i++ {
src[i] = "value"
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = DeepCopy(src)
}
}
func BenchmarkDeepCopyTree(b *testing.B) {
// A tree of (3+1) levels with fanout 4: 1+4+16+64 = 85 nodes.
src := newBenchTree(3, 4)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = DeepCopy(src)
}
}