-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_bench_test.go
45 lines (41 loc) · 1.06 KB
/
model_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
package bitknn_test
import (
"fmt"
"testing"
"github.com/keilerkonzept/bitknn"
"github.com/keilerkonzept/bitknn/internal/testrandom"
)
func BenchmarkModel(b *testing.B) {
type bench struct {
dataSize []int
k []int
}
benches := []bench{
{dataSize: []int{100}, k: []int{3, 10}},
{dataSize: []int{1000, 1_000_000}, k: []int{3, 10, 100}},
}
for _, bench := range benches {
for _, dataSize := range bench.dataSize {
for _, k := range bench.k {
data := testrandom.Data(dataSize)
labels := testrandom.Labels(dataSize)
model := bitknn.Fit(data, labels)
query := testrandom.Query()
b.Run(fmt.Sprintf("Op=Predict_bits=64_N=%d_k=%d", dataSize, k), func(b *testing.B) {
model.PreallocateHeap(k)
b.ResetTimer()
for n := 0; n < b.N; n++ {
model.Predict(k, query, bitknn.DiscardVotes)
}
})
b.Run(fmt.Sprintf("Op=Find_bits=64_N=%d_k=%d", dataSize, k), func(b *testing.B) {
model.PreallocateHeap(k)
b.ResetTimer()
for n := 0; n < b.N; n++ {
model.Find(k, query)
}
})
}
}
}
}