File: benchDot_test.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (92 lines) | stat: -rw-r--r-- 2,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright ©2017 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package f32

import (
	"fmt"
	"testing"
)

var (
	benchSink   float32
	benchSink64 float64
)

func BenchmarkDotUnitary(t *testing.B) {
	const name = "DotUnitary"
	for _, v := range []int64{1, 2, 3, 4, 5, 10, 100, 1e3, 5e3, 1e4, 5e4} {
		t.Run(fmt.Sprintf("%s-%d", name, v), func(b *testing.B) {
			x, y := x[:v], y[:v]
			b.SetBytes(32 * v)
			for i := 0; i < b.N; i++ {
				benchSink = DotUnitary(x, y)
			}
		})
	}
}

func BenchmarkDdotUnitary(t *testing.B) {
	const name = "DdotUnitary"
	for _, v := range []int64{1, 2, 3, 4, 5, 10, 100, 1e3, 5e3, 1e4, 5e4} {
		t.Run(fmt.Sprintf("%s-%d", name, v), func(b *testing.B) {
			x, y := x[:v], y[:v]
			b.SetBytes(32 * v)
			for i := 0; i < b.N; i++ {
				benchSink64 = DdotUnitary(x, y)
			}
		})
	}
}

var incsDot = []struct {
	len int
	inc []int
}{
	{1, []int{1}},
	{3, []int{1, 2, 4, 10}},
	{10, []int{1, 2, 4, 10}},
	{30, []int{1, 2, 4, 10}},
	{1e2, []int{1, 2, 4, 10}},
	{3e2, []int{1, 2, 4, 10}},
	{1e3, []int{1, 2, 4, 10}},
	{3e3, []int{1, 2, 4, 10}},
	{1e4, []int{1, 2, 4, 10, -1, -2, -4, -10}},
}

func BenchmarkDotInc(t *testing.B) {
	const name = "DotInc"
	for _, tt := range incsDot {
		for _, inc := range tt.inc {
			t.Run(fmt.Sprintf("%s-%d-inc(%d)", name, tt.len, inc), func(b *testing.B) {
				b.SetBytes(int64(32 * tt.len))
				idx := 0
				if inc < 0 {
					idx = (-tt.len + 1) * inc
				}
				for i := 0; i < b.N; i++ {
					benchSink = DotInc(x, y, uintptr(tt.len), uintptr(inc), uintptr(inc), uintptr(idx), uintptr(idx))
				}
			})
		}
	}
}

func BenchmarkDdotInc(t *testing.B) {
	const name = "DdotInc"
	for _, tt := range incsDot {
		for _, inc := range tt.inc {
			t.Run(fmt.Sprintf("%s-%d-inc(%d)", name, tt.len, inc), func(b *testing.B) {
				b.SetBytes(int64(32 * tt.len))
				idx := 0
				if inc < 0 {
					idx = (-tt.len + 1) * inc
				}
				for i := 0; i < b.N; i++ {
					benchSink64 = DdotInc(x, y, uintptr(tt.len), uintptr(inc), uintptr(inc), uintptr(idx), uintptr(idx))
				}
			})
		}
	}
}