From e84c1e3741bd7f7b3be8a424ee142005b1e7601f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 18 Sep 2015 20:10:55 +0200 Subject: [PATCH] Make read benchmark smarter when extending file --- main_test.go | 11 ++++++++--- 1 file 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)