forked from ahmetb/go-linq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
63 lines (55 loc) · 1.28 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
package linq
import "testing"
const (
size = 1000000
)
func BenchmarkSelectWhereFirst(b *testing.B) {
for n := 0; n < b.N; n++ {
Range(1, size).Select(func(i interface{}) interface{} {
return -i.(int)
}).Where(func(i interface{}) bool {
return i.(int) > -1000
}).First()
}
}
func BenchmarkSelectWhereFirst_generics(b *testing.B) {
for n := 0; n < b.N; n++ {
Range(1, size).SelectT(func(i int) int {
return -i
}).WhereT(func(i int) bool {
return i > -1000
}).First()
}
}
func BenchmarkSum(b *testing.B) {
for n := 0; n < b.N; n++ {
Range(1, size).Where(func(i interface{}) bool {
return i.(int)%2 == 0
}).SumInts()
}
}
func BenchmarkSum_generics(b *testing.B) {
for n := 0; n < b.N; n++ {
Range(1, size).WhereT(func(i int) bool {
return i%2 == 0
}).SumInts()
}
}
func BenchmarkZipSkipTake(b *testing.B) {
for n := 0; n < b.N; n++ {
Range(1, size).Zip(Range(1, size).Select(func(i interface{}) interface{} {
return i.(int) * 2
}), func(i, j interface{}) interface{} {
return i.(int) + j.(int)
}).Skip(2).Take(5)
}
}
func BenchmarkZipSkipTake_generics(b *testing.B) {
for n := 0; n < b.N; n++ {
Range(1, size).ZipT(Range(1, size).SelectT(func(i int) int {
return i * 2
}), func(i, j int) int {
return i + j
}).Skip(2).Take(5)
}
}