github.com/gopherd/gonum@v0.0.4/internal/asm/f64/benchScal_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 f64_test
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	. "github.com/gopherd/gonum/internal/asm/f64"
    12  )
    13  
    14  var uniScal = []int64{1, 3, 10, 30, 1e2, 3e2, 1e3, 3e3, 1e4, 3e4}
    15  
    16  func BenchmarkScalUnitary(t *testing.B) {
    17  	tstName := "ScalUnitary"
    18  	for _, ln := range uniScal {
    19  		t.Run(fmt.Sprintf("%s-%d", tstName, ln), func(b *testing.B) {
    20  			b.SetBytes(64 * ln)
    21  			x := x[:ln]
    22  			b.ResetTimer()
    23  			for i := 0; i < b.N; i++ {
    24  				ScalUnitary(a, x)
    25  			}
    26  		})
    27  	}
    28  }
    29  
    30  func BenchmarkScalUnitaryTo(t *testing.B) {
    31  	tstName := "ScalUnitaryTo"
    32  	for _, ln := range uniScal {
    33  		t.Run(fmt.Sprintf("%s-%d", tstName, ln), func(b *testing.B) {
    34  			b.SetBytes(64 * ln)
    35  			x, y := x[:ln], y[:ln]
    36  			b.ResetTimer()
    37  			for i := 0; i < b.N; i++ {
    38  				ScalUnitaryTo(y, a, x)
    39  			}
    40  		})
    41  	}
    42  }
    43  
    44  var incScal = []struct {
    45  	len uintptr
    46  	inc []int
    47  }{
    48  	{1, []int{1}},
    49  	{3, []int{1, 2, 4, 10}},
    50  	{10, []int{1, 2, 4, 10}},
    51  	{30, []int{1, 2, 4, 10}},
    52  	{1e2, []int{1, 2, 4, 10}},
    53  	{3e2, []int{1, 2, 4, 10}},
    54  	{1e3, []int{1, 2, 4, 10}},
    55  	{3e3, []int{1, 2, 4, 10}},
    56  	{1e4, []int{1, 2, 4, 10}},
    57  }
    58  
    59  func BenchmarkScalInc(t *testing.B) {
    60  	tstName := "ScalInc"
    61  	for _, tt := range incScal {
    62  		for _, inc := range tt.inc {
    63  			t.Run(fmt.Sprintf("%s-%d-inc(%d)", tstName, tt.len, inc), func(b *testing.B) {
    64  				b.SetBytes(int64(64 * tt.len))
    65  				tstInc := uintptr(inc)
    66  				for i := 0; i < b.N; i++ {
    67  					ScalInc(a, x, uintptr(tt.len), tstInc)
    68  				}
    69  			})
    70  		}
    71  	}
    72  }
    73  
    74  func BenchmarkScalIncTo(t *testing.B) {
    75  	tstName := "ScalIncTo"
    76  	for _, tt := range incScal {
    77  		for _, inc := range tt.inc {
    78  			t.Run(fmt.Sprintf("%s-%d-inc(%d)", tstName, tt.len, inc), func(b *testing.B) {
    79  				b.SetBytes(int64(64 * tt.len))
    80  				tstInc := uintptr(inc)
    81  				for i := 0; i < b.N; i++ {
    82  					ScalIncTo(z, tstInc, a, x, uintptr(tt.len), tstInc)
    83  				}
    84  			})
    85  		}
    86  	}
    87  }