-
Notifications
You must be signed in to change notification settings - Fork 0
/
slices_benchmark_test.go
73 lines (67 loc) · 1.51 KB
/
slices_benchmark_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
package slices
import (
"testing"
)
func generateDataSet(n int) []int {
data := make([]int, n)
for i := 0; i < n; i++ {
data[i] = i
}
return data
}
func benchmarkSimulator(i int) {
// do nothing
}
func BenchmarkForEachParallel(b *testing.B) {
b.ReportAllocs()
tests := []struct {
name string
input []int
fn func(int)
parallelism int
}{
{
name: "100000 Elements with Parallelism of 4",
input: generateDataSet(100000),
fn: benchmarkSimulator,
parallelism: 4,
},
{
name: "100000 Elements with Parallelism of 8",
input: generateDataSet(100000),
fn: benchmarkSimulator,
parallelism: 8,
},
{
name: "1000000 Elements with Parallelism of 4",
input: generateDataSet(1000000),
fn: benchmarkSimulator,
parallelism: 4,
},
{
name: "1000000 Elements with Parallelism of 8",
input: generateDataSet(1000000),
fn: benchmarkSimulator,
parallelism: 8,
},
{
name: "10000000 Elements with Parallelism of 4",
input: generateDataSet(10000000),
fn: benchmarkSimulator,
parallelism: 4,
},
{
name: "10000000 Elements with Parallelism of 4",
input: generateDataSet(10000000),
fn: benchmarkSimulator,
parallelism: 8,
},
}
for _, test := range tests {
b.Run(test.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
ForEachParallel(test.input, test.fn, test.parallelism)
}
})
}
}