Skip to content

Commit

Permalink
blas/gonum: use sub-benchmarks in BenchmarkZher
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-ch committed Aug 16, 2017
1 parent 2e2b0b5 commit 803a38d
Showing 1 changed file with 33 additions and 43 deletions.
76 changes: 33 additions & 43 deletions blas/gonum/level2cmplx128_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,48 @@
// 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"
)

func benchmarkZher(b *testing.B, uplo blas.Uplo, n, inc int) {
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)
for i := range a {
a[i] = complex(rnd.NormFloat64(), rnd.NormFloat64())
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
impl.Zher(uplo, n, alpha, x, inc, a, n)
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 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) }
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, 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, benchSinkZ, n)
copy(benchSinkZ, a)
}
})
}

0 comments on commit 803a38d

Please sign in to comment.