-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_wide_bench_test.go
64 lines (61 loc) · 1.91 KB
/
model_wide_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
package bitknn_test
import (
"fmt"
"testing"
"github.com/keilerkonzept/bitknn"
"github.com/keilerkonzept/bitknn/internal/testrandom"
"github.com/keilerkonzept/bitknn/pack"
)
func BenchmarkWideModel(b *testing.B) {
type bench struct {
dim []int
dataSize []int
k []int
batch []int
}
benches := []bench{
{dim: []int{1, 2, 10}, dataSize: []int{100}, k: []int{3, 10}, batch: nil},
{dim: []int{1}, dataSize: []int{1000, 1_000_000}, k: []int{3, 10, 100}, batch: nil},
{dim: []int{2, 10}, dataSize: []int{1000, 1_000_000}, k: []int{3, 10, 100}, batch: []int{1000}},
{dim: []int{128}, dataSize: []int{1_000_000}, k: []int{10}, batch: []int{1000}},
}
for _, bench := range benches {
for _, dim := range bench.dim {
for _, dataSize := range bench.dataSize {
for _, k := range bench.k {
data := testrandom.WideData(dim, dataSize)
pack.ReallocateFlat(data)
labels := testrandom.Labels(dataSize)
model := bitknn.FitWide(data, labels)
query := testrandom.WideQuery(dim)
b.Run(fmt.Sprintf("Op=Predict_bits=%d_N=%d_k=%d", dim*64, 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=%d_N=%d_k=%d", dim*64, dataSize, k), func(b *testing.B) {
model.PreallocateHeap(k)
b.ResetTimer()
for n := 0; n < b.N; n++ {
model.Find(k, query)
}
})
for _, batchSize := range bench.batch {
batchSize = min(batchSize, dataSize)
batchSize = max(batchSize, k)
batch := make([]uint32, batchSize)
b.Run(fmt.Sprintf("Op=FindV_batch=%d_bits=%d_N=%d_k=%d", batchSize, dim*64, dataSize, k), func(b *testing.B) {
model.PreallocateHeap(k)
b.ResetTimer()
for n := 0; n < b.N; n++ {
model.FindV(k, query, batch)
}
})
}
}
}
}
}
}