blas/gonum: use sub-benchmarks in BenchmarkZher
MODIFY
blas/gonum/level2cmplx128_bench_test.go
blas/gonum/level2cmplx128_bench_test.go
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build go1.7
+
package gonum
import (
+ "fmt"
"math/rand"
"testing"
"gonum.org/v1/gonum/blas"
)
+var benchSinkZ []complex128
+
+func BenchmarkZher(b *testing.B) {
+ for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
+ for _, n := range []int{10, 100, 1000, 10000} {
+ for _, inc := range []int{1, 10, 1000} {
+ benchmarkZher(b, uplo, n, inc)
+ }
+ }
+ }
+}
+
func benchmarkZher(b *testing.B, uplo blas.Uplo, n, inc int) {
+ b.Run(fmt.Sprintf("Uplo%d-N%d-Inc%d", uplo, n, inc), func(b *testing.B) {
rnd := rand.New(rand.NewSource(1))
alpha := rnd.NormFloat64()
x := make([]complex128, (n-1)*inc+1)
for i := range x {
x[i] = complex(rnd.NormFloat64(), rnd.NormFloat64())
}
- a := make([]complex128, n*n)
+ a := make([]complex128, len(benchSinkZ))
for i := range a {
a[i] = complex(rnd.NormFloat64(), rnd.NormFloat64())
}
+ benchSinkZ = make([]complex128, n*n)
+ copy(benchSinkZ, a)
b.ResetTimer()
for i := 0; i < b.N; i++ {
- impl.Zher(uplo, n, alpha, x, inc, a, n)
+ impl.Zher(uplo, n, alpha, x, inc, benchSinkZ, n)
+ copy(benchSinkZ, a)
}
+ })
}
-
-func BenchmarkZherUpperN10Inc1(b *testing.B) { benchmarkZher(b, blas.Upper, 10, 1) }
-func BenchmarkZherUpperN100Inc1(b *testing.B) { benchmarkZher(b, blas.Upper, 100, 1) }
-func BenchmarkZherUpperN1000Inc1(b *testing.B) { benchmarkZher(b, blas.Upper, 1000, 1) }
-func BenchmarkZherUpperN10000Inc1(b *testing.B) { benchmarkZher(b, blas.Upper, 10000, 1) }
-
-func BenchmarkZherUpperN10Inc10(b *testing.B) { benchmarkZher(b, blas.Upper, 10, 10) }
-func BenchmarkZherUpperN100Inc10(b *testing.B) { benchmarkZher(b, blas.Upper, 100, 10) }
-func BenchmarkZherUpperN1000Inc10(b *testing.B) { benchmarkZher(b, blas.Upper, 1000, 10) }
-func BenchmarkZherUpperN10000Inc10(b *testing.B) { benchmarkZher(b, blas.Upper, 10000, 10) }
-
-func BenchmarkZherUpperN10Inc1000(b *testing.B) { benchmarkZher(b, blas.Upper, 10, 1000) }
-func BenchmarkZherUpperN100Inc1000(b *testing.B) { benchmarkZher(b, blas.Upper, 100, 1000) }
-func BenchmarkZherUpperN1000Inc1000(b *testing.B) { benchmarkZher(b, blas.Upper, 1000, 1000) }
-func BenchmarkZherUpperN10000Inc1000(b *testing.B) { benchmarkZher(b, blas.Upper, 10000, 1000) }
-
-func BenchmarkZherLowerN10Inc1(b *testing.B) { benchmarkZher(b, blas.Lower, 10, 1) }
-func BenchmarkZherLowerN100Inc1(b *testing.B) { benchmarkZher(b, blas.Lower, 100, 1) }
-func BenchmarkZherLowerN1000Inc1(b *testing.B) { benchmarkZher(b, blas.Lower, 1000, 1) }
-func BenchmarkZherLowerN10000Inc1(b *testing.B) { benchmarkZher(b, blas.Lower, 10000, 1) }
-
-func BenchmarkZherLowerN10Inc10(b *testing.B) { benchmarkZher(b, blas.Lower, 10, 10) }
-func BenchmarkZherLowerN100Inc10(b *testing.B) { benchmarkZher(b, blas.Lower, 100, 10) }
-func BenchmarkZherLowerN1000Inc10(b *testing.B) { benchmarkZher(b, blas.Lower, 1000, 10) }
-func BenchmarkZherLowerN10000Inc10(b *testing.B) { benchmarkZher(b, blas.Lower, 10000, 10) }
-
-func BenchmarkZherLowerN10Inc1000(b *testing.B) { benchmarkZher(b, blas.Lower, 10, 1000) }
-func BenchmarkZherLowerN100Inc1000(b *testing.B) { benchmarkZher(b, blas.Lower, 100, 1000) }
-func BenchmarkZherLowerN1000Inc1000(b *testing.B) { benchmarkZher(b, blas.Lower, 1000, 1000) }
-func BenchmarkZherLowerN10000Inc1000(b *testing.B) { benchmarkZher(b, blas.Lower, 10000, 1000) }

blas/gonum: use sub-benchmarks in BenchmarkZher