1// Copyright ©2016 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.
4
5package f64_test
6
7import (
8	"math"
9	"testing"
10
11	. "gonum.org/v1/gonum/internal/asm/f64"
12)
13
14func benchL1Norm(f func(x []float64) float64, sz int, t *testing.B) {
15	dst := y[:sz]
16	for i := 0; i < t.N; i++ {
17		f(dst)
18	}
19}
20
21var naiveL1Norm = func(x []float64) (sum float64) {
22	for _, v := range x {
23		sum += math.Abs(v)
24	}
25	return sum
26}
27
28func BenchmarkL1Norm1(t *testing.B)      { benchL1Norm(L1Norm, 1, t) }
29func BenchmarkL1Norm2(t *testing.B)      { benchL1Norm(L1Norm, 2, t) }
30func BenchmarkL1Norm3(t *testing.B)      { benchL1Norm(L1Norm, 3, t) }
31func BenchmarkL1Norm4(t *testing.B)      { benchL1Norm(L1Norm, 4, t) }
32func BenchmarkL1Norm5(t *testing.B)      { benchL1Norm(L1Norm, 5, t) }
33func BenchmarkL1Norm10(t *testing.B)     { benchL1Norm(L1Norm, 10, t) }
34func BenchmarkL1Norm100(t *testing.B)    { benchL1Norm(L1Norm, 100, t) }
35func BenchmarkL1Norm1000(t *testing.B)   { benchL1Norm(L1Norm, 1000, t) }
36func BenchmarkL1Norm10000(t *testing.B)  { benchL1Norm(L1Norm, 10000, t) }
37func BenchmarkL1Norm100000(t *testing.B) { benchL1Norm(L1Norm, 100000, t) }
38func BenchmarkL1Norm500000(t *testing.B) { benchL1Norm(L1Norm, 500000, t) }
39
40func BenchmarkLL1Norm1(t *testing.B)      { benchL1Norm(naiveL1Norm, 1, t) }
41func BenchmarkLL1Norm2(t *testing.B)      { benchL1Norm(naiveL1Norm, 2, t) }
42func BenchmarkLL1Norm3(t *testing.B)      { benchL1Norm(naiveL1Norm, 3, t) }
43func BenchmarkLL1Norm4(t *testing.B)      { benchL1Norm(naiveL1Norm, 4, t) }
44func BenchmarkLL1Norm5(t *testing.B)      { benchL1Norm(naiveL1Norm, 5, t) }
45func BenchmarkLL1Norm10(t *testing.B)     { benchL1Norm(naiveL1Norm, 10, t) }
46func BenchmarkLL1Norm100(t *testing.B)    { benchL1Norm(naiveL1Norm, 100, t) }
47func BenchmarkLL1Norm1000(t *testing.B)   { benchL1Norm(naiveL1Norm, 1000, t) }
48func BenchmarkLL1Norm10000(t *testing.B)  { benchL1Norm(naiveL1Norm, 10000, t) }
49func BenchmarkLL1Norm100000(t *testing.B) { benchL1Norm(naiveL1Norm, 100000, t) }
50func BenchmarkLL1Norm500000(t *testing.B) { benchL1Norm(naiveL1Norm, 500000, t) }
51
52func benchL1NormInc(t *testing.B, ln, inc int, f func(x []float64, n, incX int) float64) {
53	for i := 0; i < t.N; i++ {
54		f(x, ln, inc)
55	}
56}
57
58var naiveL1NormInc = func(x []float64, n, incX int) (sum float64) {
59	for i := 0; i < n*incX; i += incX {
60		sum += math.Abs(x[i])
61	}
62	return sum
63}
64
65func BenchmarkF64L1NormIncN1Inc1(b *testing.B) { benchL1NormInc(b, 1, 1, L1NormInc) }
66
67func BenchmarkF64L1NormIncN2Inc1(b *testing.B)  { benchL1NormInc(b, 2, 1, L1NormInc) }
68func BenchmarkF64L1NormIncN2Inc2(b *testing.B)  { benchL1NormInc(b, 2, 2, L1NormInc) }
69func BenchmarkF64L1NormIncN2Inc4(b *testing.B)  { benchL1NormInc(b, 2, 4, L1NormInc) }
70func BenchmarkF64L1NormIncN2Inc10(b *testing.B) { benchL1NormInc(b, 2, 10, L1NormInc) }
71
72func BenchmarkF64L1NormIncN3Inc1(b *testing.B)  { benchL1NormInc(b, 3, 1, L1NormInc) }
73func BenchmarkF64L1NormIncN3Inc2(b *testing.B)  { benchL1NormInc(b, 3, 2, L1NormInc) }
74func BenchmarkF64L1NormIncN3Inc4(b *testing.B)  { benchL1NormInc(b, 3, 4, L1NormInc) }
75func BenchmarkF64L1NormIncN3Inc10(b *testing.B) { benchL1NormInc(b, 3, 10, L1NormInc) }
76
77func BenchmarkF64L1NormIncN4Inc1(b *testing.B)  { benchL1NormInc(b, 4, 1, L1NormInc) }
78func BenchmarkF64L1NormIncN4Inc2(b *testing.B)  { benchL1NormInc(b, 4, 2, L1NormInc) }
79func BenchmarkF64L1NormIncN4Inc4(b *testing.B)  { benchL1NormInc(b, 4, 4, L1NormInc) }
80func BenchmarkF64L1NormIncN4Inc10(b *testing.B) { benchL1NormInc(b, 4, 10, L1NormInc) }
81
82func BenchmarkF64L1NormIncN10Inc1(b *testing.B)  { benchL1NormInc(b, 10, 1, L1NormInc) }
83func BenchmarkF64L1NormIncN10Inc2(b *testing.B)  { benchL1NormInc(b, 10, 2, L1NormInc) }
84func BenchmarkF64L1NormIncN10Inc4(b *testing.B)  { benchL1NormInc(b, 10, 4, L1NormInc) }
85func BenchmarkF64L1NormIncN10Inc10(b *testing.B) { benchL1NormInc(b, 10, 10, L1NormInc) }
86
87func BenchmarkF64L1NormIncN1000Inc1(b *testing.B)  { benchL1NormInc(b, 1000, 1, L1NormInc) }
88func BenchmarkF64L1NormIncN1000Inc2(b *testing.B)  { benchL1NormInc(b, 1000, 2, L1NormInc) }
89func BenchmarkF64L1NormIncN1000Inc4(b *testing.B)  { benchL1NormInc(b, 1000, 4, L1NormInc) }
90func BenchmarkF64L1NormIncN1000Inc10(b *testing.B) { benchL1NormInc(b, 1000, 10, L1NormInc) }
91
92func BenchmarkF64L1NormIncN100000Inc1(b *testing.B)  { benchL1NormInc(b, 100000, 1, L1NormInc) }
93func BenchmarkF64L1NormIncN100000Inc2(b *testing.B)  { benchL1NormInc(b, 100000, 2, L1NormInc) }
94func BenchmarkF64L1NormIncN100000Inc4(b *testing.B)  { benchL1NormInc(b, 100000, 4, L1NormInc) }
95func BenchmarkF64L1NormIncN100000Inc10(b *testing.B) { benchL1NormInc(b, 100000, 10, L1NormInc) }
96
97func BenchmarkLF64L1NormIncN1Inc1(b *testing.B) { benchL1NormInc(b, 1, 1, naiveL1NormInc) }
98
99func BenchmarkLF64L1NormIncN2Inc1(b *testing.B)  { benchL1NormInc(b, 2, 1, naiveL1NormInc) }
100func BenchmarkLF64L1NormIncN2Inc2(b *testing.B)  { benchL1NormInc(b, 2, 2, naiveL1NormInc) }
101func BenchmarkLF64L1NormIncN2Inc4(b *testing.B)  { benchL1NormInc(b, 2, 4, naiveL1NormInc) }
102func BenchmarkLF64L1NormIncN2Inc10(b *testing.B) { benchL1NormInc(b, 2, 10, naiveL1NormInc) }
103
104func BenchmarkLF64L1NormIncN3Inc1(b *testing.B)  { benchL1NormInc(b, 3, 1, naiveL1NormInc) }
105func BenchmarkLF64L1NormIncN3Inc2(b *testing.B)  { benchL1NormInc(b, 3, 2, naiveL1NormInc) }
106func BenchmarkLF64L1NormIncN3Inc4(b *testing.B)  { benchL1NormInc(b, 3, 4, naiveL1NormInc) }
107func BenchmarkLF64L1NormIncN3Inc10(b *testing.B) { benchL1NormInc(b, 3, 10, naiveL1NormInc) }
108
109func BenchmarkLF64L1NormIncN4Inc1(b *testing.B)  { benchL1NormInc(b, 4, 1, naiveL1NormInc) }
110func BenchmarkLF64L1NormIncN4Inc2(b *testing.B)  { benchL1NormInc(b, 4, 2, naiveL1NormInc) }
111func BenchmarkLF64L1NormIncN4Inc4(b *testing.B)  { benchL1NormInc(b, 4, 4, naiveL1NormInc) }
112func BenchmarkLF64L1NormIncN4Inc10(b *testing.B) { benchL1NormInc(b, 4, 10, naiveL1NormInc) }
113
114func BenchmarkLF64L1NormIncN10Inc1(b *testing.B)  { benchL1NormInc(b, 10, 1, naiveL1NormInc) }
115func BenchmarkLF64L1NormIncN10Inc2(b *testing.B)  { benchL1NormInc(b, 10, 2, naiveL1NormInc) }
116func BenchmarkLF64L1NormIncN10Inc4(b *testing.B)  { benchL1NormInc(b, 10, 4, naiveL1NormInc) }
117func BenchmarkLF64L1NormIncN10Inc10(b *testing.B) { benchL1NormInc(b, 10, 10, naiveL1NormInc) }
118
119func BenchmarkLF64L1NormIncN1000Inc1(b *testing.B)  { benchL1NormInc(b, 1000, 1, naiveL1NormInc) }
120func BenchmarkLF64L1NormIncN1000Inc2(b *testing.B)  { benchL1NormInc(b, 1000, 2, naiveL1NormInc) }
121func BenchmarkLF64L1NormIncN1000Inc4(b *testing.B)  { benchL1NormInc(b, 1000, 4, naiveL1NormInc) }
122func BenchmarkLF64L1NormIncN1000Inc10(b *testing.B) { benchL1NormInc(b, 1000, 10, naiveL1NormInc) }
123
124func BenchmarkLF64L1NormIncN100000Inc1(b *testing.B)  { benchL1NormInc(b, 100000, 1, naiveL1NormInc) }
125func BenchmarkLF64L1NormIncN100000Inc2(b *testing.B)  { benchL1NormInc(b, 100000, 2, naiveL1NormInc) }
126func BenchmarkLF64L1NormIncN100000Inc4(b *testing.B)  { benchL1NormInc(b, 100000, 4, naiveL1NormInc) }
127func BenchmarkLF64L1NormIncN100000Inc10(b *testing.B) { benchL1NormInc(b, 100000, 10, naiveL1NormInc) }
128
129func benchAdd(f func(dst, s []float64), sz int, t *testing.B) {
130	dst, s := y[:sz], x[:sz]
131	for i := 0; i < t.N; i++ {
132		f(dst, s)
133	}
134}
135
136var naiveAdd = func(dst, s []float64) {
137	for i, v := range s {
138		dst[i] += v
139	}
140}
141
142func BenchmarkAdd1(t *testing.B)      { benchAdd(Add, 1, t) }
143func BenchmarkAdd2(t *testing.B)      { benchAdd(Add, 2, t) }
144func BenchmarkAdd3(t *testing.B)      { benchAdd(Add, 3, t) }
145func BenchmarkAdd4(t *testing.B)      { benchAdd(Add, 4, t) }
146func BenchmarkAdd5(t *testing.B)      { benchAdd(Add, 5, t) }
147func BenchmarkAdd10(t *testing.B)     { benchAdd(Add, 10, t) }
148func BenchmarkAdd100(t *testing.B)    { benchAdd(Add, 100, t) }
149func BenchmarkAdd1000(t *testing.B)   { benchAdd(Add, 1000, t) }
150func BenchmarkAdd10000(t *testing.B)  { benchAdd(Add, 10000, t) }
151func BenchmarkAdd100000(t *testing.B) { benchAdd(Add, 100000, t) }
152func BenchmarkAdd500000(t *testing.B) { benchAdd(Add, 500000, t) }
153
154func BenchmarkLAdd1(t *testing.B)      { benchAdd(naiveAdd, 1, t) }
155func BenchmarkLAdd2(t *testing.B)      { benchAdd(naiveAdd, 2, t) }
156func BenchmarkLAdd3(t *testing.B)      { benchAdd(naiveAdd, 3, t) }
157func BenchmarkLAdd4(t *testing.B)      { benchAdd(naiveAdd, 4, t) }
158func BenchmarkLAdd5(t *testing.B)      { benchAdd(naiveAdd, 5, t) }
159func BenchmarkLAdd10(t *testing.B)     { benchAdd(naiveAdd, 10, t) }
160func BenchmarkLAdd100(t *testing.B)    { benchAdd(naiveAdd, 100, t) }
161func BenchmarkLAdd1000(t *testing.B)   { benchAdd(naiveAdd, 1000, t) }
162func BenchmarkLAdd10000(t *testing.B)  { benchAdd(naiveAdd, 10000, t) }
163func BenchmarkLAdd100000(t *testing.B) { benchAdd(naiveAdd, 100000, t) }
164func BenchmarkLAdd500000(t *testing.B) { benchAdd(naiveAdd, 500000, t) }
165
166func benchAddConst(f func(a float64, x []float64), sz int, t *testing.B) {
167	a, x := 1., x[:sz]
168	for i := 0; i < t.N; i++ {
169		f(a, x)
170	}
171}
172
173var naiveAddConst = func(a float64, x []float64) {
174	for i := range x {
175		x[i] += a
176	}
177}
178
179func BenchmarkAddConst1(t *testing.B)      { benchAddConst(AddConst, 1, t) }
180func BenchmarkAddConst2(t *testing.B)      { benchAddConst(AddConst, 2, t) }
181func BenchmarkAddConst3(t *testing.B)      { benchAddConst(AddConst, 3, t) }
182func BenchmarkAddConst4(t *testing.B)      { benchAddConst(AddConst, 4, t) }
183func BenchmarkAddConst5(t *testing.B)      { benchAddConst(AddConst, 5, t) }
184func BenchmarkAddConst10(t *testing.B)     { benchAddConst(AddConst, 10, t) }
185func BenchmarkAddConst100(t *testing.B)    { benchAddConst(AddConst, 100, t) }
186func BenchmarkAddConst1000(t *testing.B)   { benchAddConst(AddConst, 1000, t) }
187func BenchmarkAddConst10000(t *testing.B)  { benchAddConst(AddConst, 10000, t) }
188func BenchmarkAddConst100000(t *testing.B) { benchAddConst(AddConst, 100000, t) }
189func BenchmarkAddConst500000(t *testing.B) { benchAddConst(AddConst, 500000, t) }
190
191func BenchmarkLAddConst1(t *testing.B)      { benchAddConst(naiveAddConst, 1, t) }
192func BenchmarkLAddConst2(t *testing.B)      { benchAddConst(naiveAddConst, 2, t) }
193func BenchmarkLAddConst3(t *testing.B)      { benchAddConst(naiveAddConst, 3, t) }
194func BenchmarkLAddConst4(t *testing.B)      { benchAddConst(naiveAddConst, 4, t) }
195func BenchmarkLAddConst5(t *testing.B)      { benchAddConst(naiveAddConst, 5, t) }
196func BenchmarkLAddConst10(t *testing.B)     { benchAddConst(naiveAddConst, 10, t) }
197func BenchmarkLAddConst100(t *testing.B)    { benchAddConst(naiveAddConst, 100, t) }
198func BenchmarkLAddConst1000(t *testing.B)   { benchAddConst(naiveAddConst, 1000, t) }
199func BenchmarkLAddConst10000(t *testing.B)  { benchAddConst(naiveAddConst, 10000, t) }
200func BenchmarkLAddConst100000(t *testing.B) { benchAddConst(naiveAddConst, 100000, t) }
201func BenchmarkLAddConst500000(t *testing.B) { benchAddConst(naiveAddConst, 500000, t) }
202
203func benchCumSum(f func(a, b []float64) []float64, sz int, t *testing.B) {
204	a, b := x[:sz], y[:sz]
205	for i := 0; i < t.N; i++ {
206		f(a, b)
207	}
208}
209
210var naiveCumSum = func(dst, s []float64) []float64 {
211	if len(s) == 0 {
212		return dst
213	}
214	dst[0] = s[0]
215	for i, v := range s[1:] {
216		dst[i+1] = dst[i] + v
217	}
218	return dst
219}
220
221func BenchmarkCumSum1(t *testing.B)      { benchCumSum(CumSum, 1, t) }
222func BenchmarkCumSum2(t *testing.B)      { benchCumSum(CumSum, 2, t) }
223func BenchmarkCumSum3(t *testing.B)      { benchCumSum(CumSum, 3, t) }
224func BenchmarkCumSum4(t *testing.B)      { benchCumSum(CumSum, 4, t) }
225func BenchmarkCumSum5(t *testing.B)      { benchCumSum(CumSum, 5, t) }
226func BenchmarkCumSum10(t *testing.B)     { benchCumSum(CumSum, 10, t) }
227func BenchmarkCumSum100(t *testing.B)    { benchCumSum(CumSum, 100, t) }
228func BenchmarkCumSum1000(t *testing.B)   { benchCumSum(CumSum, 1000, t) }
229func BenchmarkCumSum10000(t *testing.B)  { benchCumSum(CumSum, 10000, t) }
230func BenchmarkCumSum100000(t *testing.B) { benchCumSum(CumSum, 100000, t) }
231func BenchmarkCumSum500000(t *testing.B) { benchCumSum(CumSum, 500000, t) }
232
233func BenchmarkLCumSum1(t *testing.B)      { benchCumSum(naiveCumSum, 1, t) }
234func BenchmarkLCumSum2(t *testing.B)      { benchCumSum(naiveCumSum, 2, t) }
235func BenchmarkLCumSum3(t *testing.B)      { benchCumSum(naiveCumSum, 3, t) }
236func BenchmarkLCumSum4(t *testing.B)      { benchCumSum(naiveCumSum, 4, t) }
237func BenchmarkLCumSum5(t *testing.B)      { benchCumSum(naiveCumSum, 5, t) }
238func BenchmarkLCumSum10(t *testing.B)     { benchCumSum(naiveCumSum, 10, t) }
239func BenchmarkLCumSum100(t *testing.B)    { benchCumSum(naiveCumSum, 100, t) }
240func BenchmarkLCumSum1000(t *testing.B)   { benchCumSum(naiveCumSum, 1000, t) }
241func BenchmarkLCumSum10000(t *testing.B)  { benchCumSum(naiveCumSum, 10000, t) }
242func BenchmarkLCumSum100000(t *testing.B) { benchCumSum(naiveCumSum, 100000, t) }
243func BenchmarkLCumSum500000(t *testing.B) { benchCumSum(naiveCumSum, 500000, t) }
244
245func benchCumProd(f func(a, b []float64) []float64, sz int, t *testing.B) {
246	a, b := x[:sz], y[:sz]
247	for i := 0; i < t.N; i++ {
248		f(a, b)
249	}
250}
251
252var naiveCumProd = func(dst, s []float64) []float64 {
253	if len(s) == 0 {
254		return dst
255	}
256	dst[0] = s[0]
257	for i, v := range s[1:] {
258		dst[i+1] = dst[i] + v
259	}
260	return dst
261}
262
263func BenchmarkCumProd1(t *testing.B)      { benchCumProd(CumProd, 1, t) }
264func BenchmarkCumProd2(t *testing.B)      { benchCumProd(CumProd, 2, t) }
265func BenchmarkCumProd3(t *testing.B)      { benchCumProd(CumProd, 3, t) }
266func BenchmarkCumProd4(t *testing.B)      { benchCumProd(CumProd, 4, t) }
267func BenchmarkCumProd5(t *testing.B)      { benchCumProd(CumProd, 5, t) }
268func BenchmarkCumProd10(t *testing.B)     { benchCumProd(CumProd, 10, t) }
269func BenchmarkCumProd100(t *testing.B)    { benchCumProd(CumProd, 100, t) }
270func BenchmarkCumProd1000(t *testing.B)   { benchCumProd(CumProd, 1000, t) }
271func BenchmarkCumProd10000(t *testing.B)  { benchCumProd(CumProd, 10000, t) }
272func BenchmarkCumProd100000(t *testing.B) { benchCumProd(CumProd, 100000, t) }
273func BenchmarkCumProd500000(t *testing.B) { benchCumProd(CumProd, 500000, t) }
274
275func BenchmarkLCumProd1(t *testing.B)      { benchCumProd(naiveCumProd, 1, t) }
276func BenchmarkLCumProd2(t *testing.B)      { benchCumProd(naiveCumProd, 2, t) }
277func BenchmarkLCumProd3(t *testing.B)      { benchCumProd(naiveCumProd, 3, t) }
278func BenchmarkLCumProd4(t *testing.B)      { benchCumProd(naiveCumProd, 4, t) }
279func BenchmarkLCumProd5(t *testing.B)      { benchCumProd(naiveCumProd, 5, t) }
280func BenchmarkLCumProd10(t *testing.B)     { benchCumProd(naiveCumProd, 10, t) }
281func BenchmarkLCumProd100(t *testing.B)    { benchCumProd(naiveCumProd, 100, t) }
282func BenchmarkLCumProd1000(t *testing.B)   { benchCumProd(naiveCumProd, 1000, t) }
283func BenchmarkLCumProd10000(t *testing.B)  { benchCumProd(naiveCumProd, 10000, t) }
284func BenchmarkLCumProd100000(t *testing.B) { benchCumProd(naiveCumProd, 100000, t) }
285func BenchmarkLCumProd500000(t *testing.B) { benchCumProd(naiveCumProd, 500000, t) }
286
287func benchDiv(f func(a, b []float64), sz int, t *testing.B) {
288	a, b := x[:sz], y[:sz]
289	for i := 0; i < t.N; i++ {
290		f(a, b)
291	}
292}
293
294var naiveDiv = func(a, b []float64) {
295	for i, v := range b {
296		a[i] /= v
297	}
298}
299
300func BenchmarkDiv1(t *testing.B)      { benchDiv(Div, 1, t) }
301func BenchmarkDiv2(t *testing.B)      { benchDiv(Div, 2, t) }
302func BenchmarkDiv3(t *testing.B)      { benchDiv(Div, 3, t) }
303func BenchmarkDiv4(t *testing.B)      { benchDiv(Div, 4, t) }
304func BenchmarkDiv5(t *testing.B)      { benchDiv(Div, 5, t) }
305func BenchmarkDiv10(t *testing.B)     { benchDiv(Div, 10, t) }
306func BenchmarkDiv100(t *testing.B)    { benchDiv(Div, 100, t) }
307func BenchmarkDiv1000(t *testing.B)   { benchDiv(Div, 1000, t) }
308func BenchmarkDiv10000(t *testing.B)  { benchDiv(Div, 10000, t) }
309func BenchmarkDiv100000(t *testing.B) { benchDiv(Div, 100000, t) }
310func BenchmarkDiv500000(t *testing.B) { benchDiv(Div, 500000, t) }
311
312func BenchmarkLDiv1(t *testing.B)      { benchDiv(naiveDiv, 1, t) }
313func BenchmarkLDiv2(t *testing.B)      { benchDiv(naiveDiv, 2, t) }
314func BenchmarkLDiv3(t *testing.B)      { benchDiv(naiveDiv, 3, t) }
315func BenchmarkLDiv4(t *testing.B)      { benchDiv(naiveDiv, 4, t) }
316func BenchmarkLDiv5(t *testing.B)      { benchDiv(naiveDiv, 5, t) }
317func BenchmarkLDiv10(t *testing.B)     { benchDiv(naiveDiv, 10, t) }
318func BenchmarkLDiv100(t *testing.B)    { benchDiv(naiveDiv, 100, t) }
319func BenchmarkLDiv1000(t *testing.B)   { benchDiv(naiveDiv, 1000, t) }
320func BenchmarkLDiv10000(t *testing.B)  { benchDiv(naiveDiv, 10000, t) }
321func BenchmarkLDiv100000(t *testing.B) { benchDiv(naiveDiv, 100000, t) }
322func BenchmarkLDiv500000(t *testing.B) { benchDiv(naiveDiv, 500000, t) }
323
324func benchDivTo(f func(dst, a, b []float64) []float64, sz int, t *testing.B) {
325	dst, a, b := z[:sz], x[:sz], y[:sz]
326	for i := 0; i < t.N; i++ {
327		f(dst, a, b)
328	}
329}
330
331var naiveDivTo = func(dst, s, t []float64) []float64 {
332	for i, v := range s {
333		dst[i] = v / t[i]
334	}
335	return dst
336}
337
338func BenchmarkDivTo1(t *testing.B)      { benchDivTo(DivTo, 1, t) }
339func BenchmarkDivTo2(t *testing.B)      { benchDivTo(DivTo, 2, t) }
340func BenchmarkDivTo3(t *testing.B)      { benchDivTo(DivTo, 3, t) }
341func BenchmarkDivTo4(t *testing.B)      { benchDivTo(DivTo, 4, t) }
342func BenchmarkDivTo5(t *testing.B)      { benchDivTo(DivTo, 5, t) }
343func BenchmarkDivTo10(t *testing.B)     { benchDivTo(DivTo, 10, t) }
344func BenchmarkDivTo100(t *testing.B)    { benchDivTo(DivTo, 100, t) }
345func BenchmarkDivTo1000(t *testing.B)   { benchDivTo(DivTo, 1000, t) }
346func BenchmarkDivTo10000(t *testing.B)  { benchDivTo(DivTo, 10000, t) }
347func BenchmarkDivTo100000(t *testing.B) { benchDivTo(DivTo, 100000, t) }
348func BenchmarkDivTo500000(t *testing.B) { benchDivTo(DivTo, 500000, t) }
349
350func BenchmarkLDivTo1(t *testing.B)      { benchDivTo(naiveDivTo, 1, t) }
351func BenchmarkLDivTo2(t *testing.B)      { benchDivTo(naiveDivTo, 2, t) }
352func BenchmarkLDivTo3(t *testing.B)      { benchDivTo(naiveDivTo, 3, t) }
353func BenchmarkLDivTo4(t *testing.B)      { benchDivTo(naiveDivTo, 4, t) }
354func BenchmarkLDivTo5(t *testing.B)      { benchDivTo(naiveDivTo, 5, t) }
355func BenchmarkLDivTo10(t *testing.B)     { benchDivTo(naiveDivTo, 10, t) }
356func BenchmarkLDivTo100(t *testing.B)    { benchDivTo(naiveDivTo, 100, t) }
357func BenchmarkLDivTo1000(t *testing.B)   { benchDivTo(naiveDivTo, 1000, t) }
358func BenchmarkLDivTo10000(t *testing.B)  { benchDivTo(naiveDivTo, 10000, t) }
359func BenchmarkLDivTo100000(t *testing.B) { benchDivTo(naiveDivTo, 100000, t) }
360func BenchmarkLDivTo500000(t *testing.B) { benchDivTo(naiveDivTo, 500000, t) }
361
362func benchL1Dist(f func(a, b []float64) float64, sz int, t *testing.B) {
363	a, b := x[:sz], y[:sz]
364	for i := 0; i < t.N; i++ {
365		f(a, b)
366	}
367}
368
369var naiveL1Dist = func(s, t []float64) float64 {
370	var norm float64
371	for i, v := range s {
372		norm += math.Abs(t[i] - v)
373	}
374	return norm
375}
376
377func BenchmarkL1Dist1(t *testing.B)      { benchL1Dist(L1Dist, 1, t) }
378func BenchmarkL1Dist2(t *testing.B)      { benchL1Dist(L1Dist, 2, t) }
379func BenchmarkL1Dist3(t *testing.B)      { benchL1Dist(L1Dist, 3, t) }
380func BenchmarkL1Dist4(t *testing.B)      { benchL1Dist(L1Dist, 4, t) }
381func BenchmarkL1Dist5(t *testing.B)      { benchL1Dist(L1Dist, 5, t) }
382func BenchmarkL1Dist10(t *testing.B)     { benchL1Dist(L1Dist, 10, t) }
383func BenchmarkL1Dist100(t *testing.B)    { benchL1Dist(L1Dist, 100, t) }
384func BenchmarkL1Dist1000(t *testing.B)   { benchL1Dist(L1Dist, 1000, t) }
385func BenchmarkL1Dist10000(t *testing.B)  { benchL1Dist(L1Dist, 10000, t) }
386func BenchmarkL1Dist100000(t *testing.B) { benchL1Dist(L1Dist, 100000, t) }
387func BenchmarkL1Dist500000(t *testing.B) { benchL1Dist(L1Dist, 500000, t) }
388
389func BenchmarkLL1Dist1(t *testing.B)      { benchL1Dist(naiveL1Dist, 1, t) }
390func BenchmarkLL1Dist2(t *testing.B)      { benchL1Dist(naiveL1Dist, 2, t) }
391func BenchmarkLL1Dist3(t *testing.B)      { benchL1Dist(naiveL1Dist, 3, t) }
392func BenchmarkLL1Dist4(t *testing.B)      { benchL1Dist(naiveL1Dist, 4, t) }
393func BenchmarkLL1Dist5(t *testing.B)      { benchL1Dist(naiveL1Dist, 5, t) }
394func BenchmarkLL1Dist10(t *testing.B)     { benchL1Dist(naiveL1Dist, 10, t) }
395func BenchmarkLL1Dist100(t *testing.B)    { benchL1Dist(naiveL1Dist, 100, t) }
396func BenchmarkLL1Dist1000(t *testing.B)   { benchL1Dist(naiveL1Dist, 1000, t) }
397func BenchmarkLL1Dist10000(t *testing.B)  { benchL1Dist(naiveL1Dist, 10000, t) }
398func BenchmarkLL1Dist100000(t *testing.B) { benchL1Dist(naiveL1Dist, 100000, t) }
399func BenchmarkLL1Dist500000(t *testing.B) { benchL1Dist(naiveL1Dist, 500000, t) }
400
401func benchLinfDist(f func(a, b []float64) float64, sz int, t *testing.B) {
402	a, b := x[:sz], y[:sz]
403	for i := 0; i < t.N; i++ {
404		f(a, b)
405	}
406}
407
408var naiveLinfDist = func(s, t []float64) float64 {
409	var norm float64
410	if len(s) == 0 {
411		return 0
412	}
413	norm = math.Abs(t[0] - s[0])
414	for i, v := range s[1:] {
415		absDiff := math.Abs(t[i+1] - v)
416		if absDiff > norm || math.IsNaN(norm) {
417			norm = absDiff
418		}
419	}
420	return norm
421}
422
423func BenchmarkLinfDist1(t *testing.B)      { benchLinfDist(LinfDist, 1, t) }
424func BenchmarkLinfDist2(t *testing.B)      { benchLinfDist(LinfDist, 2, t) }
425func BenchmarkLinfDist3(t *testing.B)      { benchLinfDist(LinfDist, 3, t) }
426func BenchmarkLinfDist4(t *testing.B)      { benchLinfDist(LinfDist, 4, t) }
427func BenchmarkLinfDist5(t *testing.B)      { benchLinfDist(LinfDist, 5, t) }
428func BenchmarkLinfDist10(t *testing.B)     { benchLinfDist(LinfDist, 10, t) }
429func BenchmarkLinfDist100(t *testing.B)    { benchLinfDist(LinfDist, 100, t) }
430func BenchmarkLinfDist1000(t *testing.B)   { benchLinfDist(LinfDist, 1000, t) }
431func BenchmarkLinfDist10000(t *testing.B)  { benchLinfDist(LinfDist, 10000, t) }
432func BenchmarkLinfDist100000(t *testing.B) { benchLinfDist(LinfDist, 100000, t) }
433func BenchmarkLinfDist500000(t *testing.B) { benchLinfDist(LinfDist, 500000, t) }
434
435func BenchmarkLLinfDist1(t *testing.B)      { benchLinfDist(naiveLinfDist, 1, t) }
436func BenchmarkLLinfDist2(t *testing.B)      { benchLinfDist(naiveLinfDist, 2, t) }
437func BenchmarkLLinfDist3(t *testing.B)      { benchLinfDist(naiveLinfDist, 3, t) }
438func BenchmarkLLinfDist4(t *testing.B)      { benchLinfDist(naiveLinfDist, 4, t) }
439func BenchmarkLLinfDist5(t *testing.B)      { benchLinfDist(naiveLinfDist, 5, t) }
440func BenchmarkLLinfDist10(t *testing.B)     { benchLinfDist(naiveLinfDist, 10, t) }
441func BenchmarkLLinfDist100(t *testing.B)    { benchLinfDist(naiveLinfDist, 100, t) }
442func BenchmarkLLinfDist1000(t *testing.B)   { benchLinfDist(naiveLinfDist, 1000, t) }
443func BenchmarkLLinfDist10000(t *testing.B)  { benchLinfDist(naiveLinfDist, 10000, t) }
444func BenchmarkLLinfDist100000(t *testing.B) { benchLinfDist(naiveLinfDist, 100000, t) }
445func BenchmarkLLinfDist500000(t *testing.B) { benchLinfDist(naiveLinfDist, 500000, t) }
446