-
Notifications
You must be signed in to change notification settings - Fork 0
/
nunela_test.go
80 lines (61 loc) · 1.42 KB
/
nunela_test.go
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
// Copyright © The Nune Author. All rights reserved.
package nunela_test
import (
"testing"
"time"
"github.com/vorduin/nune"
)
func benchmarkMicro(b *testing.B, f func()) {
b.ResetTimer()
start := time.Now()
for i := 0; i < b.N; i++ {
f()
}
execTime := time.Since(start)
b.ReportMetric(0, "ns/op")
b.ReportMetric((1e6*execTime.Seconds())/float64(b.N), "μs/op")
}
func benchmarkMilli(b *testing.B, f func()) {
b.ResetTimer()
start := time.Now()
for i := 0; i < b.N; i++ {
f()
}
execTime := time.Since(start)
b.ReportMetric(0, "ns/op")
b.ReportMetric((1e3*execTime.Seconds())/float64(b.N), "ms/op")
}
type TestsT float64
func newTensor(num int) nune.Tensor[TestsT] {
return nune.Range[TestsT](0, num*num, 1).Reshape(num, num)
}
func benchmarkOp(b *testing.B, f func(nune.Tensor[TestsT])) {
b.Run("1e4Float64Procs1", func(b *testing.B) {
nune.EnvConfig.NumCPU = 1
tensor := newTensor(1e2)
benchmarkMilli(b, func() {
f(tensor)
})
})
b.Run("1e4Float64ProcsN", func(b *testing.B) {
nune.EnvConfig.NumCPU = 0
tensor := newTensor(1e2)
benchmarkMilli(b, func() {
f(tensor)
})
})
b.Run("4e4Float64Procs1", func(b *testing.B) {
nune.EnvConfig.NumCPU = 1
tensor := newTensor(2e2)
benchmarkMilli(b, func() {
f(tensor)
})
})
b.Run("4e4Float64ProcsN", func(b *testing.B) {
nune.EnvConfig.NumCPU = 0
tensor := newTensor(2e2)
benchmarkMilli(b, func() {
f(tensor)
})
})
}