-
Notifications
You must be signed in to change notification settings - Fork 225
/
benchmark_test.go
93 lines (79 loc) · 1.78 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
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)
}
}
func BenchmarkFromChannel(b *testing.B) {
for n := 0; n < b.N; n++ {
ch := make(chan interface{})
go func() {
for i := 0; i < size; i++ {
ch <- i
}
close(ch)
}()
FromChannel(ch).All(func(i interface{}) bool { return true })
}
}
func BenchmarkFromChannelT(b *testing.B) {
for n := 0; n < b.N; n++ {
ch := make(chan interface{})
go func() {
for i := 0; i < size; i++ {
ch <- i
}
close(ch)
}()
FromChannelT(ch).All(func(i interface{}) bool { return true })
}
}