OSDN Git Service

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