github.com/gopherd/gonum@v0.0.4/internal/asm/c64/benchDot_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 c64
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  var benchSink complex64
    13  
    14  func BenchmarkDotUnitary(t *testing.B) {
    15  	for _, tst := range []struct {
    16  		name string
    17  		f    func(x, y []complex64) complex64
    18  	}{
    19  		{"DotcUnitary", DotcUnitary},
    20  		{"DotuUnitary", DotuUnitary},
    21  	} {
    22  		for _, v := range []int64{1, 2, 3, 4, 5, 10, 100, 1e3, 5e3, 1e4, 5e4} {
    23  			t.Run(fmt.Sprintf("%s-%d", tst.name, v), func(b *testing.B) {
    24  				x, y := x[:v], y[:v]
    25  				b.SetBytes(128 * v)
    26  				for i := 0; i < b.N; i++ {
    27  					benchSink = tst.f(x, y)
    28  				}
    29  			})
    30  		}
    31  	}
    32  }
    33  
    34  func BenchmarkDotInc(t *testing.B) {
    35  	for _, tst := range []struct {
    36  		name string
    37  		f    func(x, y []complex64, n, incX, incY, ix, iy uintptr) complex64
    38  	}{
    39  		{"DotcInc", DotcInc},
    40  		{"DotuInc", DotuInc},
    41  	} {
    42  		for _, ln := range []int{1, 2, 3, 4, 5, 10, 100, 1e3, 5e3, 1e4, 5e4} {
    43  			for _, inc := range []int{1, 2, 4, 10, -1, -2, -4, -10} {
    44  				t.Run(fmt.Sprintf("%s-%d-inc%d", tst.name, ln, inc), func(b *testing.B) {
    45  					b.SetBytes(int64(128 * ln))
    46  					var idx int
    47  					if inc < 0 {
    48  						idx = (-ln + 1) * inc
    49  					}
    50  					for i := 0; i < b.N; i++ {
    51  						benchSink = tst.f(x, y, uintptr(ln), uintptr(inc), uintptr(inc), uintptr(idx), uintptr(idx))
    52  					}
    53  				})
    54  			}
    55  		}
    56  	}
    57  }