-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch_test.go
50 lines (45 loc) · 1.12 KB
/
branch_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
package oakmux
import (
"fmt"
"strings"
"testing"
_ "embed" // for test data
)
//go:embed test/data/strings.txt
var testStringsRaw string
var testStrings = strings.Split(strings.TrimSpace(testStringsRaw), "\n")
func BenchmarkNodeBranches(b *testing.B) {
for i := 2; i < 25; i++ {
searchKey := testStrings[i-1]
var node *Node
b.Run(fmt.Sprintf("branchList of %d items", i), func(b *testing.B) {
var branches = make(branchList, 0, i)
for _, key := range testStrings[:i] {
branches = append(branches, keyedBranch{
key: key,
node: &Node{},
})
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
node = branches.Get(searchKey)
}
})
if node == nil {
b.Fatalf("search key %q was never found during benchmark", searchKey)
}
b.Run(fmt.Sprintf("branchMap of %d items", i), func(b *testing.B) {
var branches = make(branchMap)
for _, key := range testStrings[:i] {
branches[key] = &Node{}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
node = branches.Get(searchKey)
}
})
if node == nil {
b.Fatalf("search key %q was never found during benchmark", searchKey)
}
}
}