-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphed_test.go
More file actions
83 lines (70 loc) · 2.26 KB
/
Copy pathgraphed_test.go
File metadata and controls
83 lines (70 loc) · 2.26 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
package graphed
import (
"fmt"
"testing"
)
// benchmarkNodeStoreSize runs AddNode operations for n nodes
func benchmarkNodeStoreSize(n int, b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
store := NewNodeStore()
b.StartTimer()
// Add root node
store.AddNode("root", "")
// Add n customer nodes
for j := 0; j < n; j++ {
customerName := fmt.Sprintf("customer%d", j)
store.AddNode(customerName, "root")
// Add locations for each customer
for k := 0; k < 2; k++ {
locationName := fmt.Sprintf("%s.location%d", customerName, k)
store.AddNode(locationName, customerName)
// Add services for each location
serviceName := fmt.Sprintf("%s.service1", locationName)
store.AddNode(serviceName, locationName)
// Add logs for each service
logsName := fmt.Sprintf("%s.logs", serviceName)
store.AddNode(logsName, serviceName)
// Add log entries
for l := 0; l < 3; l++ {
logEntryName := fmt.Sprintf("AD.logs%d", l)
store.AddNode(logEntryName, logsName)
}
}
}
}
}
// Benchmark different sizes of node trees
func BenchmarkNodeStore10(b *testing.B) { benchmarkNodeStoreSize(10, b) }
func BenchmarkNodeStore100(b *testing.B) { benchmarkNodeStoreSize(100, b) }
func BenchmarkNodeStore1000(b *testing.B) { benchmarkNodeStoreSize(1000, b) }
func BenchmarkNodeStore10000(b *testing.B) { benchmarkNodeStoreSize(10000, b) }
// Benchmark individual operations
func BenchmarkAddNode(b *testing.B) {
store := NewNodeStore()
store.AddNode("root", "")
b.ResetTimer()
for i := 0; i < b.N; i++ {
nodeName := fmt.Sprintf("node%d", i)
store.AddNode(nodeName, "root")
}
}
func BenchmarkNodeLookup(b *testing.B) {
store := NewNodeStore()
store.AddNode("root", "")
store.AddNode("test_node1", "root")
store.AddNode("test_node2", "root")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
store.AddNode("test_service", "test_node1")
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = store.Node("test_node")
}
}