-
Notifications
You must be signed in to change notification settings - Fork 272
/
benchmark_test.go
124 lines (103 loc) · 2.31 KB
/
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
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
113
114
115
116
117
118
119
120
121
122
123
124
package funk
import (
"math/rand"
"testing"
)
const (
seed = 918234565
sliceSize = 3614562
)
func sliceGenerator(size uint, r *rand.Rand) (out []int64) {
for i := uint(0); i < size; i++ {
out = append(out, rand.Int63())
}
return
}
func BenchmarkSubtract(b *testing.B) {
r := rand.New(rand.NewSource(seed))
testData := sliceGenerator(sliceSize, r)
what := sliceGenerator(sliceSize, r)
b.Run("Subtract", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Subtract(testData, what)
}
})
}
func BenchmarkContains(b *testing.B) {
r := rand.New(rand.NewSource(seed))
testData := sliceGenerator(sliceSize, r)
what := r.Int63()
b.Run("ContainsInt64", func(b *testing.B) {
for n := 0; n < b.N; n++ {
ContainsInt64(testData, what)
}
})
b.Run("IndexOfInt64", func(b *testing.B) {
for n := 0; n < b.N; n++ {
IndexOfInt64(testData, what)
}
})
b.Run("Contains", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Contains(testData, what)
}
})
}
func BenchmarkUniq(b *testing.B) {
r := rand.New(rand.NewSource(seed))
testData := sliceGenerator(sliceSize, r)
b.Run("UniqInt64", func(b *testing.B) {
for n := 0; n < b.N; n++ {
UniqInt64(testData)
}
})
b.Run("Uniq", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Uniq(testData)
}
})
}
func BenchmarkSum(b *testing.B) {
r := rand.New(rand.NewSource(seed))
testData := sliceGenerator(sliceSize, r)
b.Run("SumInt64", func(b *testing.B) {
for n := 0; n < b.N; n++ {
SumInt64(testData)
}
})
b.Run("Sum", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Sum(testData)
}
})
}
func BenchmarkDrop(b *testing.B) {
r := rand.New(rand.NewSource(seed))
testData := sliceGenerator(sliceSize, r)
b.Run("DropInt64", func(b *testing.B) {
for n := 0; n < b.N; n++ {
DropInt64(testData, 1)
}
})
b.Run("Drop", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Drop(testData, 1)
}
})
}
func BenchmarkJoin(b *testing.B) {
r := rand.New(rand.NewSource(seed))
fullArr := sliceGenerator(sliceSize, r)
leftArr := fullArr[:sliceSize/3*2]
rightArr := fullArr[sliceSize/3*1:]
b.Run("InnerJoinInt64", func(b *testing.B) {
for n := 0; n < b.N; n++ {
JoinInt64(leftArr, rightArr, InnerJoinInt64)
}
})
b.Run("InnerJoin", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Join(leftArr, rightArr, InnerJoin)
}
})
}