gonum.org/v1/gonum@v0.14.0/blas/gonum/level2cmplx128_bench_test.go (about)

     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.
     4  
     5  package gonum
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"golang.org/x/exp/rand"
    12  
    13  	"gonum.org/v1/gonum/blas"
    14  )
    15  
    16  var benchSinkZ []complex128
    17  
    18  func BenchmarkZher(b *testing.B) {
    19  	for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
    20  		for _, n := range []int{10, 100, 1000, 10000} {
    21  			for _, inc := range []int{1, 10, 1000} {
    22  				benchmarkZher(b, uplo, n, inc)
    23  			}
    24  		}
    25  	}
    26  }
    27  
    28  func benchmarkZher(b *testing.B, uplo blas.Uplo, n, inc int) {
    29  	b.Run(fmt.Sprintf("Uplo%d-N%d-Inc%d", uplo, n, inc), func(b *testing.B) {
    30  		rnd := rand.New(rand.NewSource(1))
    31  		alpha := rnd.NormFloat64()
    32  		x := make([]complex128, (n-1)*inc+1)
    33  		for i := range x {
    34  			x[i] = complex(rnd.NormFloat64(), rnd.NormFloat64())
    35  		}
    36  		a := make([]complex128, len(benchSinkZ))
    37  		for i := range a {
    38  			a[i] = complex(rnd.NormFloat64(), rnd.NormFloat64())
    39  		}
    40  		benchSinkZ = make([]complex128, n*n)
    41  		copy(benchSinkZ, a)
    42  		b.ResetTimer()
    43  		for i := 0; i < b.N; i++ {
    44  			impl.Zher(uplo, n, alpha, x, inc, benchSinkZ, n)
    45  			copy(benchSinkZ, a)
    46  		}
    47  	})
    48  }