aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-18 20:10:55 +0200
committerJakob Unterwurzacher2015-09-18 20:10:55 +0200
commite84c1e3741bd7f7b3be8a424ee142005b1e7601f (patch)
tree7537c77866dc20f396fde0553b29f4489e1b0a20 /main_test.go
parent67fe4557e5225f5be1687aca3d1934ad1141a684 (diff)
Make read benchmark smarter when extending file
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/main_test.go b/main_test.go
index 0dfa06a..667d626 100644
--- a/main_test.go
+++ b/main_test.go
@@ -136,14 +136,19 @@ func BenchmarkStreamRead(t *testing.B) {
buf := make([]byte, 1024*1024)
t.SetBytes(int64(len(buf)))
- if t.N > 100 {
+ fn := plainDir + "BenchmarkWrite"
+ fi, _ := os.Stat(fn)
+ mb := int(fi.Size() / 1024 / 1024)
+
+ if t.N > mb {
// Grow file so we can satisfy the test
- f2, err := os.OpenFile(plainDir + "BenchmarkWrite", os.O_WRONLY | os.O_APPEND, 0666)
+ fmt.Printf("Growing file to %d MB\n", t.N)
+ f2, err := os.OpenFile(fn, os.O_WRONLY | os.O_APPEND, 0666)
if err != nil {
fmt.Println(err)
t.FailNow()
}
- for h := 0; h < t.N - 100 ; h++ {
+ for h := 0; h < t.N - mb ; h++ {
_, err = f2.Write(buf)
if err != nil {
fmt.Println(err)