forked from deepfabric/bkdtree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
68 lines (61 loc) · 1.37 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package bkdtree
import (
"testing"
)
func BenchmarkBkdInsert(b *testing.B) {
t0mCap := 1000
leafCap := 50
intraCap := 4
numDims := 2
bytesPerDim := 4
dir := "/tmp"
prefix := "bkd"
bkd, err := NewBkdTree(t0mCap, leafCap, intraCap, numDims, bytesPerDim, dir, prefix)
if err != nil {
b.Fatalf("%+v", err)
}
//fmt.Printf("created BkdTree %v\n", bkd)
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := bkd.Insert(Point{[]uint64{uint64(i), uint64(i)}, uint64(i)})
if err != nil {
b.Fatalf("bkd.Insert failed, i=%v, err: %+v", i, err)
}
}
return
}
func BenchmarkBkdErase(b *testing.B) {
var maxVal uint64 = 1000
bkd, points, err := prepareBkdTree(maxVal)
if err != nil {
b.Fatalf("%+v", err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = bkd.Erase(points[i])
if err != nil {
b.Fatalf("%+v", err)
}
}
}
func BenchmarkBkdIntersect(b *testing.B) {
var maxVal uint64 = 1000
bkd, points, err := prepareBkdTree(maxVal)
if err != nil {
b.Fatalf("%+v", err)
}
var lowPoint, highPoint Point
var visitor *IntersectCollector
lowPoint = points[7]
highPoint = lowPoint
visitor = &IntersectCollector{lowPoint, highPoint, make([]Point, 0)}
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = bkd.Intersect(visitor)
if err != nil {
b.Fatalf("%+v", err)
} else if len(visitor.Points) <= 0 {
b.Errorf("found 0 matchs, however some expected")
}
}
}