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

     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 testlapack
     6  
     7  import (
     8  	"testing"
     9  
    10  	"math/rand"
    11  
    12  	"github.com/gopherd/gonum/blas/blas64"
    13  	"github.com/gopherd/gonum/lapack"
    14  )
    15  
    16  var resultGeneral blas64.General
    17  
    18  func DgeevBenchmark(b *testing.B, impl Dgeever) {
    19  	rnd := rand.New(rand.NewSource(1))
    20  	benchmarks := []struct {
    21  		name string
    22  		a    blas64.General
    23  	}{
    24  		{"AntisymRandom3", NewAntisymRandom(3, rnd).Matrix()},
    25  		{"AntisymRandom4", NewAntisymRandom(4, rnd).Matrix()},
    26  		{"AntisymRandom5", NewAntisymRandom(5, rnd).Matrix()},
    27  		{"AntisymRandom10", NewAntisymRandom(10, rnd).Matrix()},
    28  		{"AntisymRandom50", NewAntisymRandom(50, rnd).Matrix()},
    29  		{"AntisymRandom100", NewAntisymRandom(100, rnd).Matrix()},
    30  		{"AntisymRandom200", NewAntisymRandom(200, rnd).Matrix()},
    31  		{"AntisymRandom500", NewAntisymRandom(500, rnd).Matrix()},
    32  		{"Circulant3", Circulant(3).Matrix()},
    33  		{"Circulant4", Circulant(4).Matrix()},
    34  		{"Circulant5", Circulant(5).Matrix()},
    35  		{"Circulant10", Circulant(10).Matrix()},
    36  		{"Circulant50", Circulant(50).Matrix()},
    37  		{"Circulant100", Circulant(100).Matrix()},
    38  		{"Circulant200", Circulant(200).Matrix()},
    39  		{"Circulant500", Circulant(500).Matrix()},
    40  	}
    41  	for _, bm := range benchmarks {
    42  		n := bm.a.Rows
    43  		a := zeros(n, n, n)
    44  		vl := zeros(n, n, n)
    45  		vr := zeros(n, n, n)
    46  		wr := make([]float64, n)
    47  		wi := make([]float64, n)
    48  		work := make([]float64, 1)
    49  		impl.Dgeev(lapack.LeftEVCompute, lapack.RightEVCompute, n, a.Data, a.Stride, wr, wi, vl.Data, vl.Stride, vr.Data, vr.Stride, work, -1)
    50  		work = make([]float64, int(work[0]))
    51  		b.Run(bm.name, func(b *testing.B) {
    52  			for i := 0; i < b.N; i++ {
    53  				b.StopTimer()
    54  				copyGeneral(a, bm.a)
    55  				b.StartTimer()
    56  				impl.Dgeev(lapack.LeftEVCompute, lapack.RightEVCompute, n, a.Data, a.Stride, wr, wi,
    57  					vl.Data, vl.Stride, vr.Data, vr.Stride, work, len(work))
    58  			}
    59  			resultGeneral = a
    60  		})
    61  	}
    62  }