gonum.org/v1/gonum@v0.14.0/internal/asm/f32/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 f32
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  var (
    13  	benchSink   float32
    14  	benchSink64 float64
    15  )
    16  
    17  func BenchmarkDotUnitary(t *testing.B) {
    18  	const name = "DotUnitary"
    19  	for _, v := range []int64{1, 2, 3, 4, 5, 10, 100, 1e3, 5e3, 1e4, 5e4} {
    20  		t.Run(fmt.Sprintf("%s-%d", name, v), func(b *testing.B) {
    21  			x, y := x[:v], y[:v]
    22  			b.SetBytes(32 * v)
    23  			for i := 0; i < b.N; i++ {
    24  				benchSink = DotUnitary(x, y)
    25  			}
    26  		})
    27  	}
    28  }
    29  
    30  func BenchmarkDdotUnitary(t *testing.B) {
    31  	const name = "DdotUnitary"
    32  	for _, v := range []int64{1, 2, 3, 4, 5, 10, 100, 1e3, 5e3, 1e4, 5e4} {
    33  		t.Run(fmt.Sprintf("%s-%d", name, v), func(b *testing.B) {
    34  			x, y := x[:v], y[:v]
    35  			b.SetBytes(32 * v)
    36  			for i := 0; i < b.N; i++ {
    37  				benchSink64 = DdotUnitary(x, y)
    38  			}
    39  		})
    40  	}
    41  }
    42  
    43  var incsDot = []struct {
    44  	len int
    45  	inc []int
    46  }{
    47  	{1, []int{1}},
    48  	{3, []int{1, 2, 4, 10}},
    49  	{10, []int{1, 2, 4, 10}},
    50  	{30, []int{1, 2, 4, 10}},
    51  	{1e2, []int{1, 2, 4, 10}},
    52  	{3e2, []int{1, 2, 4, 10}},
    53  	{1e3, []int{1, 2, 4, 10}},
    54  	{3e3, []int{1, 2, 4, 10}},
    55  	{1e4, []int{1, 2, 4, 10, -1, -2, -4, -10}},
    56  }
    57  
    58  func BenchmarkDotInc(t *testing.B) {
    59  	const name = "DotInc"
    60  	for _, tt := range incsDot {
    61  		for _, inc := range tt.inc {
    62  			t.Run(fmt.Sprintf("%s-%d-inc(%d)", name, tt.len, inc), func(b *testing.B) {
    63  				b.SetBytes(int64(32 * tt.len))
    64  				idx := 0
    65  				if inc < 0 {
    66  					idx = (-tt.len + 1) * inc
    67  				}
    68  				for i := 0; i < b.N; i++ {
    69  					benchSink = DotInc(x, y, uintptr(tt.len), uintptr(inc), uintptr(inc), uintptr(idx), uintptr(idx))
    70  				}
    71  			})
    72  		}
    73  	}
    74  }
    75  
    76  func BenchmarkDdotInc(t *testing.B) {
    77  	const name = "DdotInc"
    78  	for _, tt := range incsDot {
    79  		for _, inc := range tt.inc {
    80  			t.Run(fmt.Sprintf("%s-%d-inc(%d)", name, tt.len, inc), func(b *testing.B) {
    81  				b.SetBytes(int64(32 * tt.len))
    82  				idx := 0
    83  				if inc < 0 {
    84  					idx = (-tt.len + 1) * inc
    85  				}
    86  				for i := 0; i < b.N; i++ {
    87  					benchSink64 = DdotInc(x, y, uintptr(tt.len), uintptr(inc), uintptr(inc), uintptr(idx), uintptr(idx))
    88  				}
    89  			})
    90  		}
    91  	}
    92  }