-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_bench_test.go
42 lines (38 loc) · 967 Bytes
/
main_bench_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
package main_test
import (
"context"
"io/ioutil"
"os"
"path"
"testing"
"github.com/askiada/external-sort/file"
"github.com/askiada/external-sort/vector"
"github.com/askiada/external-sort/vector/key"
"github.com/stretchr/testify/assert"
)
func BenchmarkMergeSort(b *testing.B) {
filename := "test.tsv"
chunkSize := 10000
bufferSize := 5000
f, err := os.Open(filename)
assert.NoError(b, err)
fI := &file.Info{
Reader: f,
Allocate: vector.DefaultVector(key.AllocateInt),
OutputPath: "testdata/chunks/output.tsv",
}
chunkPaths, err := fI.CreateSortedChunks(context.Background(), "testdata/chunks", chunkSize, 100)
assert.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = fI.MergeSort(chunkPaths, bufferSize)
_ = err
}
f.Close()
dir, err := ioutil.ReadDir("testdata/chunks")
assert.NoError(b, err)
for _, d := range dir {
err = os.RemoveAll(path.Join("testdata/chunks", d.Name()))
assert.NoError(b, err)
}
}