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