-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.go
More file actions
140 lines (117 loc) · 2.87 KB
/
Copy pathrun_test.go
File metadata and controls
140 lines (117 loc) · 2.87 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"1brc/concurrent_1"
"1brc/run_1"
"1brc/run_2"
"1brc/run_3"
"1brc/run_4"
"1brc/run_5"
"1brc/run_6"
"1brc/run_7"
"1brc/run_8"
"1brc/run_9"
"bytes"
"crypto/md5"
"io"
"os"
"path/filepath"
"strings"
"testing"
)
const (
B int = 1
KB = B << 10
MB = KB << 10
GB = MB << 10
)
// ==================================================================================== //
// Benchmark
// ==================================================================================== //
// go test -run=XXX -benchmem -v -bench=BenchmarkRun9
func BenchmarkRun9(b *testing.B) {
for i := 0; i < b.N; i++ {
run_9.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun8(b *testing.B) {
for i := 0; i < b.N; i++ {
run_8.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun7(b *testing.B) {
for i := 0; i < b.N; i++ {
run_7.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun6(b *testing.B) {
for i := 0; i < b.N; i++ {
run_6.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun5(b *testing.B) {
for i := 0; i < b.N; i++ {
run_5.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun4(b *testing.B) {
for i := 0; i < b.N; i++ {
run_4.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun3(b *testing.B) {
for i := 0; i < b.N; i++ {
run_3.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun2(b *testing.B) {
for i := 0; i < b.N; i++ {
run_2.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkRun1(b *testing.B) {
for i := 0; i < b.N; i++ {
run_1.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
func BenchmarkConcurrent1(b *testing.B) {
for i := 0; i < b.N; i++ {
concurrent_1.Entrypoint(os.Stdout, "measurements_1b.txt")
}
}
// ==================================================================================== //
// Test
// ==================================================================================== //
func TestAll(t *testing.T) {
funcsToTest := []func(io.Writer, string){
concurrent_1.Entrypoint,
run_1.Entrypoint,
run_2.Entrypoint,
run_3.Entrypoint,
run_4.Entrypoint,
run_5.Entrypoint,
run_6.Entrypoint,
run_7.Entrypoint,
run_8.Entrypoint,
run_9.Entrypoint,
}
matches, _ := filepath.Glob("samples/*.txt")
t.Logf("testing with files: %v \n", matches)
for _, match := range matches {
t.Logf("testing file: %s", match)
expectedPath := strings.TrimSuffix(match, ".txt") + ".out"
expectedb, _ := os.ReadFile(expectedPath)
expected := md5.Sum(expectedb)
for i, fun := range funcsToTest {
t.Logf("\t testing run: %d", i+1)
var buf bytes.Buffer
fun(&buf, match)
res := md5.Sum(buf.Bytes())
if expected != res {
t.Logf("\t\t run_%d failed", i+1)
t.Logf("\t\t produced hash %x expected %x \n", res, expected)
t.Logf("\t\t produced %s \n", buf.String())
t.Fail()
}
}
}
}