File: dot_product_test.go

package info (click to toggle)
python-peachpy 0.0~git20211013.257881e-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,452 kB
  • sloc: python: 29,286; ansic: 54; makefile: 44; cpp: 31
file content (55 lines) | stat: -rw-r--r-- 1,115 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
package blas
 
import (
	"testing"
	"math/rand"
)
 
func benchmarkDotProduct(bench *testing.B, size int, useGo bool) {
	x := make([]float32, size)
	y := make([]float32, size)

	r := rand.New(rand.NewSource(42))
	for i := 0; i < size; i++ {
		x[i] = r.Float32()
		y[i] = r.Float32()
	}

	bench.ResetTimer()
	if useGo {
		for i := 0; i < bench.N; i++ {
			var z float32 = 0.0
			for j := 0; j < size; j++ {
				z += x[j] * y[j]
			}
		}
	} else {
		for i := 0; i < bench.N; i++ {
			DotProduct(&x[0], &y[0], uint(size))
		}
	}
}

func BenchmarkDotProduct_L1_PeachPy(bench *testing.B) {
	benchmarkDotProduct(bench, 4096, false)
}

func BenchmarkDotProduct_L2_PeachPy(bench *testing.B) {
	benchmarkDotProduct(bench, 32768, false)
}

func BenchmarkDotProduct_L3_PeachPy(bench *testing.B) {
	benchmarkDotProduct(bench, 262144, false)
}

func BenchmarkDotProduct_L1_Go(bench *testing.B) {
	benchmarkDotProduct(bench, 4096, true)
}

func BenchmarkDotProduct_L2_Go(bench *testing.B) {
	benchmarkDotProduct(bench, 32768, true)
}

func BenchmarkDotProduct_L3_Go(bench *testing.B) {
	benchmarkDotProduct(bench, 262144, true)
}