-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
46 lines (38 loc) · 897 Bytes
/
main_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
package main
import (
"bufio"
"log"
"os"
"testing"
)
func Benchmark1Pick1(b *testing.B) { pickRandomN1(1, b) }
func Benchmark1Pick5(b *testing.B) { pickRandomN1(1, b) }
func Benchmark1Pick10(b *testing.B) { pickRandomN1(1, b) }
func Benchmark2Pick1(b *testing.B) { pickRandomN2(1, b) }
func Benchmark2Pick5(b *testing.B) { pickRandomN2(1, b) }
func Benchmark2Pick10(b *testing.B) { pickRandomN2(1, b) }
func pickRandomN1(c int, b *testing.B) {
f, err := os.Open("data/test_data.txt")
defer f.Close()
if err != nil {
log.Fatal(err)
}
r := bufio.NewReader(f)
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = pickRandom(c, r)
f.Seek(0, 0)
}
}
func pickRandomN2(c int, b *testing.B) {
f, err := os.Open("data/test_data.txt")
defer f.Close()
if err != nil {
log.Fatal(err)
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = pickRandom2(c, f)
f.Seek(0, 0)
}
}