-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsum_test.go
87 lines (67 loc) · 1.99 KB
/
sum_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
// +build !noasm
package simd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSumFloat64(t *testing.T) {
buf := makeBuffer(10000)
res := SumFloat64(buf)
assert.Equal(t, res, float64(49995000.0))
}
func makeBuffer(l int) []float64 {
buf := make([]float64, l)
for i := range buf {
buf[i] = float64(i)
}
return buf
}
func BenchmarkSumFloat64_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, SumFloat64)
}
func BenchmarkSumFloat64_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, SumFloat64)
}
func BenchmarkSumFloat64_Intrinsics_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, sum_float64_avx_intrinsics)
}
func BenchmarkSumFloat64_Intrinsics_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, sum_float64_avx_intrinsics)
}
func BenchmarkSumFloat64_AVX2_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, sum_float64_avx2)
}
func BenchmarkSumFloat64_AVX2_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, sum_float64_avx2)
}
func BenchmarkSumFloat64_SSE4_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, sum_float64_sse4)
}
func BenchmarkSumFloat64_SSE4_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, sum_float64_sse4)
}
func BenchmarkSumFloat64_Go_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, sum_float64_go)
}
func BenchmarkSumFloat64_Go_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, sum_float64_go)
}
func BenchmarkSumFloat64_GoUnroll4_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, sum_float64_go_unroll4)
}
func BenchmarkSumFloat64_GoUnroll4_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, sum_float64_go_unroll4)
}
func BenchmarkSumFloat64_GoUnroll8_1000(b *testing.B) {
benchmarkSumFloat64Fn(b, 1000, sum_float64_go_unroll8)
}
func BenchmarkSumFloat64_GoUnroll8_10000(b *testing.B) {
benchmarkSumFloat64Fn(b, 10000, sum_float64_go_unroll8)
}
func benchmarkSumFloat64Fn(b *testing.B, n int, fn func([]float64) float64) {
buf := makeBuffer(n)
b.SetBytes(int64(len(buf) * 8))
for i := 0; i < b.N; i++ {
fn(buf)
}
}