-
Notifications
You must be signed in to change notification settings - Fork 2
/
fsearch_bench_test.go
53 lines (43 loc) · 947 Bytes
/
fsearch_bench_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
package fsearch
import (
"fmt"
"testing"
)
func genTreePaths(sampleSize, factor int) map[string]bool {
paths := map[string]bool{"root": true}
nextLevelPaths := map[string]bool{}
for len(paths) <= sampleSize {
for pathname := range paths {
for i := 0; i < factor; i++ {
subPath := fmt.Sprintf("%s/%s", pathname, randStr.Alphabets())
nextLevelPaths[subPath] = true
}
if len(nextLevelPaths) > sampleSize {
break
}
}
paths = nextLevelPaths
nextLevelPaths = map[string]bool{}
}
return paths
}
func BenchmarkFSearch(b *testing.B) {
const (
segmentLen = 4
factor = 10
sampleSize = 10000 * 100
)
var pathnames = genTreePaths(sampleSize, factor)
fmt.Printf("bench sample size (%d)\n", len(pathnames))
fs := New("/", 0)
for pathname := range pathnames {
err := fs.AddPath(pathname)
if err != nil {
b.Fatal(err)
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
fs.Search("ab")
}
}