-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.go
95 lines (75 loc) · 1.66 KB
/
benchmark_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Copyright (C) 2024 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
// https://github.com/kshard/vector
//
package vector_test
import (
"testing"
"github.com/kshard/vector"
"github.com/kshard/vector/internal/noasm"
"github.com/kshard/vector/internal/pure"
"github.com/kshard/vector/internal/simd"
"github.com/kshard/vector/internal/vtest"
)
var (
d float32
eq bool
a = vtest.Vector()
b = vtest.Vector()
n1 = Node{ID: 1, Vector: a}
n2 = Node{ID: 2, Vector: b}
)
func BenchmarkPureEqualF32(t *testing.B) {
euc := pure.Euclidean(0)
for i := t.N; i > 0; i-- {
eq = euc.Equal(a, a)
}
}
func BenchmarkNoAsmEqualF32(t *testing.B) {
euc := noasm.Euclidean(0)
for i := t.N; i > 0; i-- {
eq = euc.Equal(a, a)
}
}
func BenchmarkPureEuclideanF32(t *testing.B) {
euc := pure.Euclidean(0)
for i := t.N; i > 0; i-- {
d = euc.Distance(a, b)
}
}
func BenchmarkNoAsmEuclideanF32(t *testing.B) {
euc := noasm.Euclidean(0)
for i := t.N; i > 0; i-- {
d = euc.Distance(a, b)
}
}
func BenchmarkSIMDEuclideanF32(t *testing.B) {
euc := simd.Euclidean(0)
for i := t.N; i > 0; i-- {
d = euc.Distance(a, b)
}
}
func BenchmarkContraMapEuclidean(t *testing.B) {
euc := vector.ContraMap[vector.F32, Node]{
Surface: vector.Euclidean(),
ContraMap: ntov,
}
for i := t.N; i > 0; i-- {
d = euc.Distance(n1, n2)
}
}
func BenchmarkPureCosineF32(t *testing.B) {
cos := pure.Cosine(0)
for i := t.N; i > 0; i-- {
d = cos.Distance(a, b)
}
}
func BenchmarkNoAsmCosineF32(t *testing.B) {
cos := noasm.Cosine(0)
for i := t.N; i > 0; i-- {
d = cos.Distance(a, b)
}
}