github.com/gopherd/gonum@v0.0.4/blas/testblas/level2bench.go (about)

     1  // Copyright ©2014 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 testblas
     6  
     7  import (
     8  	"testing"
     9  
    10  	"math/rand"
    11  
    12  	"github.com/gopherd/gonum/blas"
    13  )
    14  
    15  func DgemvBenchmark(b *testing.B, impl Dgemver, tA blas.Transpose, m, n, incX, incY int) {
    16  	var lenX, lenY int
    17  	if tA == blas.NoTrans {
    18  		lenX = n
    19  		lenY = m
    20  	} else {
    21  		lenX = m
    22  		lenY = n
    23  	}
    24  	xr := make([]float64, lenX)
    25  	for i := range xr {
    26  		xr[i] = rand.Float64()
    27  	}
    28  	x := makeIncremented(xr, incX, 0)
    29  	yr := make([]float64, lenY)
    30  	for i := range yr {
    31  		yr[i] = rand.Float64()
    32  	}
    33  	y := makeIncremented(yr, incY, 0)
    34  	a := make([]float64, m*n)
    35  	for i := range a {
    36  		a[i] = rand.Float64()
    37  	}
    38  
    39  	b.ResetTimer()
    40  	for i := 0; i < b.N; i++ {
    41  		impl.Dgemv(tA, m, n, 2, a, n, x, incX, 3, y, incY)
    42  	}
    43  }
    44  
    45  func DgerBenchmark(b *testing.B, impl Dgerer, m, n, incX, incY int) {
    46  	xr := make([]float64, m)
    47  	for i := range xr {
    48  		xr[i] = rand.Float64()
    49  	}
    50  	x := makeIncremented(xr, incX, 0)
    51  	yr := make([]float64, n)
    52  	for i := range yr {
    53  		yr[i] = rand.Float64()
    54  	}
    55  	y := makeIncremented(yr, incY, 0)
    56  	a := make([]float64, m*n)
    57  	for i := range a {
    58  		a[i] = rand.Float64()
    59  	}
    60  
    61  	b.ResetTimer()
    62  	for i := 0; i < b.N; i++ {
    63  		impl.Dger(m, n, 2, x, incX, y, incY, a, n)
    64  	}
    65  }
    66  
    67  type Sgerer interface {
    68  	Sger(m, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int)
    69  }
    70  
    71  func SgerBenchmark(b *testing.B, blasser Sgerer, m, n, incX, incY int) {
    72  	xr := make([]float32, m)
    73  	for i := range xr {
    74  		xr[i] = rand.Float32()
    75  	}
    76  	x := makeIncremented32(xr, incX, 0)
    77  	yr := make([]float32, n)
    78  	for i := range yr {
    79  		yr[i] = rand.Float32()
    80  	}
    81  	y := makeIncremented32(yr, incY, 0)
    82  	a := make([]float32, m*n)
    83  	for i := range a {
    84  		a[i] = rand.Float32()
    85  	}
    86  
    87  	b.ResetTimer()
    88  	for i := 0; i < b.N; i++ {
    89  		blasser.Sger(m, n, 2, x, incX, y, incY, a, n)
    90  	}
    91  }