-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench_test.go
112 lines (96 loc) · 2.18 KB
/
bench_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package radixsort_test
import (
"testing"
"github.com/loov/radixsort"
"github.com/zeebo/pcg"
)
type SizeBenchmark struct {
Name string
Size int
}
var BenchmarkSizes = []SizeBenchmark{
{"1e2", 1e2},
{"1e3", 1e3},
{"1e4", 1e4},
{"1e5", 1e5},
{"1e6", 1e6},
{"1e7", 1e7},
}
func bench32(b *testing.B, size int, algo func(src, dst []uint32)) {
rng := pcg.New(0)
data := make([]uint32, size)
buf := make([]uint32, len(data))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; i < len(data); i++ {
data[i] = rng.Uint32()
}
algo(data, buf)
}
}
func bench64(b *testing.B, size int, algo func(src, dst []uint64)) {
rng := pcg.New(uint64(0))
data := make([]uint64, size)
buf := make([]uint64, len(data))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; i < len(data); i++ {
data[i] = rng.Uint64()
}
algo(data, buf)
}
}
func benchUint(b *testing.B, size int, algo func(src, dst []uint)) {
rng := pcg.New(uint64(0))
data := make([]uint, size)
buf := make([]uint, len(data))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; i < len(data); i++ {
data[i] = uint(rng.Uint64())
}
algo(data, buf)
}
}
func BenchmarkPCGOverhead(b *testing.B) {
for _, bench := range BenchmarkSizes {
b.Run(bench.Name, func(b *testing.B) {
benchUint(b, bench.Size, func(x, y []uint) {})
})
}
}
func BenchmarkPCGOverhead32(b *testing.B) {
for _, bench := range BenchmarkSizes {
b.Run(bench.Name, func(b *testing.B) {
bench32(b, bench.Size, func(x, y []uint32) {})
})
}
}
func BenchmarkPCGOverhead64(b *testing.B) {
for _, bench := range BenchmarkSizes {
b.Run(bench.Name, func(b *testing.B) {
bench64(b, bench.Size, func(x, y []uint64) {})
})
}
}
func BenchmarkUint32(b *testing.B) {
for _, bench := range BenchmarkSizes {
b.Run(bench.Name, func(b *testing.B) {
bench32(b, bench.Size, radixsort.Uint32)
})
}
}
func BenchmarkUint64(b *testing.B) {
for _, bench := range BenchmarkSizes {
b.Run(bench.Name, func(b *testing.B) {
bench64(b, bench.Size, radixsort.Uint64)
})
}
}
func BenchmarkUint(b *testing.B) {
for _, bench := range BenchmarkSizes {
b.Run(bench.Name, func(b *testing.B) {
benchUint(b, bench.Size, radixsort.Uint)
})
}
}