1 // Copyright ©2017 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
18 x = make([]float64, testLen)
19 y = make([]float64, testLen)
20 z = make([]float64, testLen)
30 func BenchmarkAxpyUnitary(t *testing.B) {
31 naiveaxpyu := func(a float64, x, y []float64) {
38 f func(a float64, x, y []float64)
40 {"AxpyUnitary", AxpyUnitary},
41 {"NaiveAxpyUnitary", naiveaxpyu},
43 for _, test := range tests {
44 for _, ln := range []uintptr{1, 3, 10, 30, 1e2, 3e2, 1e3, 3e3, 1e4, 3e4, 1e5} {
45 t.Run(fmt.Sprintf("%s-%d", test.name, ln), func(b *testing.B) {
46 b.SetBytes(int64(64 * ln))
47 x, y := x[:ln], y[:ln]
49 for i := 0; i < b.N; i++ {
57 func BenchmarkAxpyUnitaryTo(t *testing.B) {
58 naiveaxpyut := func(d []float64, a float64, x, y []float64) {
65 f func(z []float64, a float64, x, y []float64)
67 {"AxpyUnitaryTo", AxpyUnitaryTo},
68 {"NaiveAxpyUnitaryTo", naiveaxpyut},
70 for _, test := range tests {
71 for _, ln := range []uintptr{1, 3, 10, 30, 1e2, 3e2, 1e3, 3e3, 1e4, 3e4, 1e5} {
72 t.Run(fmt.Sprintf("%s-%d", test.name, ln), func(b *testing.B) {
73 b.SetBytes(int64(64 * ln))
74 x, y, z := x[:ln], y[:ln], z[:ln]
76 for i := 0; i < b.N; i++ {
84 var incsAxpy = []struct {
89 {2, []int{1, 2, 4, 10}},
90 {3, []int{1, 2, 4, 10}},
91 {4, []int{1, 2, 4, 10}},
92 {5, []int{1, 2, 4, 10}},
93 {10, []int{1, 2, 4, 10}},
94 {500, []int{1, 2, 4, 10}},
95 {1e3, []int{1, 2, 4, 10}},
96 {1e4, []int{1, 2, 4, 10, -1, -2, -4, -10}},
99 func BenchmarkAxpyInc(t *testing.B) {
100 naiveaxpyinc := func(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) {
101 for i := 0; i < int(n); i++ {
102 y[iy] += alpha * x[ix]
109 f func(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr)
111 {"AxpyInc", AxpyInc},
112 {"NaiveAxpyInc", naiveaxpyinc},
114 for _, test := range tests {
115 for _, tt := range incsAxpy {
116 for _, inc := range tt.inc {
117 t.Run(fmt.Sprintf("%s-%d-inc(%d)", test.name, tt.len, inc), func(b *testing.B) {
118 b.SetBytes(int64(64 * tt.len))
119 var idx, tstInc uintptr = 0, uintptr(inc)
121 idx = uintptr((-int(tt.len) + 1) * inc)
123 for i := 0; i < b.N; i++ {
124 test.f(a, x, y, uintptr(tt.len), tstInc, tstInc, idx, idx)
132 func BenchmarkAxpyIncTo(t *testing.B) {
133 naiveaxpyincto := func(dst []float64, incDst, idst uintptr, alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) {
134 for i := 0; i < int(n); i++ {
135 dst[idst] = alpha*x[ix] + y[iy]
143 f func(dst []float64, incDst, idst uintptr, alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr)
145 {"AxpyIncTo", AxpyIncTo},
146 {"NaiveAxpyIncTo", naiveaxpyincto},
148 for _, test := range tests {
149 for _, tt := range incsAxpy {
150 for _, inc := range tt.inc {
151 t.Run(fmt.Sprintf("%s-%d-inc(%d)", test.name, tt.len, inc), func(b *testing.B) {
152 b.SetBytes(int64(64 * tt.len))
153 var idx, tstInc uintptr = 0, uintptr(inc)
155 idx = uintptr((-int(tt.len) + 1) * inc)
157 for i := 0; i < b.N; i++ {
158 test.f(z, tstInc, idx, a, x, y, uintptr(tt.len),
159 tstInc, tstInc, idx, idx)