-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
75 lines (60 loc) · 1.29 KB
/
main_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
package main
import (
"testing"
"github.com/klauspost/cpuid/v2"
"github.com/Crash129/go-simd-example/avo"
"github.com/Crash129/go-simd-example/cgo"
"github.com/Crash129/go-simd-example/gocc"
"github.com/Crash129/go-simd-example/gosimd"
)
var xs, xy, out []float32
func init() {
xs = make([]float32, 4096)
xy = make([]float32, 4096)
out = make([]float32, 4096)
for i := range xs {
xs[i] = float32(i)
xy[i] = float32(i)
}
}
func BenchmarkAvo(b *testing.B) {
if !cpuid.CPU.Has(cpuid.AVX2) {
b.Skip("no AVX2 support")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
avo.Add(xs, xy, out)
}
}
func BenchmarkGocc(b *testing.B) {
if !cpuid.CPU.Has(cpuid.AVX2) && !cpuid.CPU.Has(cpuid.ASIMD) {
b.Skip("no AVX2 or ARM SIMD support")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
gocc.Add(xs, xy, out)
}
}
func BenchmarkPlainGo(b *testing.B) {
for i := 0; i < b.N; i++ {
plainGo(xs, xy, out)
}
}
func BenchmarkGoSIMD(b *testing.B) {
if !cpuid.CPU.Has(cpuid.ASIMD) {
b.Skip("no ARM SIMD support")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
gosimd.Add(xs, xy, out)
}
}
func BenchmarkCGo(b *testing.B) {
if !cpuid.CPU.Has(cpuid.AVX2) && !cpuid.CPU.Has(cpuid.ASIMD) {
b.Skip("no AVX2 or ARM SIMD support")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
cgo.Add(xs, xy, out)
}
}