github.com/gopherd/gonum@v0.0.4/lapack/testlapack/dlantb_bench.go (about)

     1  // Copyright ©2020 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 testlapack
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"math/rand"
    12  
    13  	"github.com/gopherd/gonum/blas"
    14  	"github.com/gopherd/gonum/lapack"
    15  )
    16  
    17  var result float64
    18  
    19  func DlantbBenchmark(b *testing.B, impl Dlantber) {
    20  	rnd := rand.New(rand.NewSource(1))
    21  	for _, bm := range []struct {
    22  		n, k int
    23  	}{
    24  		{n: 10000, k: 1},
    25  		{n: 10000, k: 2},
    26  		{n: 10000, k: 100},
    27  	} {
    28  		n := bm.n
    29  		k := bm.k
    30  		lda := k + 1
    31  		for _, norm := range []lapack.MatrixNorm{lapack.MaxAbs, lapack.MaxRowSum, lapack.MaxColumnSum, lapack.Frobenius} {
    32  			var work []float64
    33  			if norm == lapack.MaxColumnSum {
    34  				work = make([]float64, n)
    35  			}
    36  			for _, uplo := range []blas.Uplo{blas.Lower, blas.Upper} {
    37  				for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
    38  					name := fmt.Sprintf("%v%v%vN=%vK=%v", normToString(norm), uploToString(uplo), diagToString(diag), n, k)
    39  					b.Run(name, func(b *testing.B) {
    40  						for i := 0; i < b.N; i++ {
    41  							b.StopTimer()
    42  							a := make([]float64, n*lda)
    43  							for i := range a {
    44  								a[i] = rnd.NormFloat64()
    45  							}
    46  							b.StartTimer()
    47  							result = impl.Dlantb(norm, uplo, diag, bm.n, bm.k, a, lda, work)
    48  						}
    49  					})
    50  				}
    51  			}
    52  		}
    53  	}
    54  }