-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
benchmark_dense_arith_test.go
91 lines (73 loc) · 2.17 KB
/
benchmark_dense_arith_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
package tensor
import (
"testing"
"gorgonia.org/vecf64"
)
func BenchmarkDense_Mul_Unsafe(b *testing.B) {
A := New(WithShape(100, 100, 2), WithBacking(Range(Float64, 0, 100*100*2)))
B := New(WithShape(100, 100, 2), WithBacking(Range(Float64, 1, (100*100*2)+1)))
for i := 0; i < b.N; i++ {
A.Mul(B, UseUnsafe())
}
}
func BenchmarkNative_Mul_Unsafe(b *testing.B) {
A := Range(Float64, 0, 100*100*2).([]float64)
B := Range(Float64, 1, (100*100*2)+1).([]float64)
f := func(a, b []float64) {
for i, v := range a {
a[i] = v * b[i]
}
}
for i := 0; i < b.N; i++ {
f(A, B)
}
}
func BenchmarkNative_Mul_Unsafe_vec(b *testing.B) {
A := Range(Float64, 0, 100*100*2).([]float64)
B := Range(Float64, 1, (100*100*2)+1).([]float64)
for i := 0; i < b.N; i++ {
vecf64.Mul(A, B)
}
}
func BenchmarkAPI_Mul_Unsafe(b *testing.B) {
A := New(WithShape(100, 100, 2), WithBacking(Range(Float64, 0, 100*100*2)))
B := New(WithShape(100, 100, 2), WithBacking(Range(Float64, 1, (100*100*2)+1)))
for i := 0; i < b.N; i++ {
Mul(A, B, UseUnsafe())
}
}
func BenchmarkDense_ContiguousSliced_Mul_Unsafe(b *testing.B) {
A := New(WithShape(4, 100, 100), WithBacking(Range(Float64, 0, 100*100*4)))
B := New(WithShape(2, 100, 100), WithBacking(Range(Float64, 1, (100*100*2)+1)))
Sliced, _ := A.Slice(makeRS(1, 3)) // result should be contiguous
for i := 0; i < b.N; i++ {
Mul(Sliced, B, UseUnsafe())
}
}
func BenchmarkDense_NonContiguousSliced_Mul_Unsafe(b *testing.B) {
A := New(WithShape(100, 4, 100), WithBacking(Range(Float64, 0, 100*100*4)))
B := New(WithShape(100, 2, 100), WithBacking(Range(Float64, 1, (100*100*2)+1)))
Sliced, _ := A.Slice(nil, makeRS(1, 3)) // result should be non-contiguous
for i := 0; i < b.N; i++ {
Mul(Sliced, B, UseUnsafe())
}
}
func BenchmarkAPI_MulScalar_Unsafe(b *testing.B) {
A := New(WithShape(100, 100, 2), WithBacking(Range(Float64, 0, 100*100*2)))
B := 3.141
for i := 0; i < b.N; i++ {
Mul(A, B, UseUnsafe())
}
}
func BenchmarkNative_MulScalar_Unsafe(b *testing.B) {
A := Range(Float64, 0, 100*100*2).([]float64)
B := 3.141
f := func(a []float64, b float64) {
for i := range a {
a[i] *= b
}
}
for i := 0; i < b.N; i++ {
f(A, B)
}
}