Make read benchmark smarter when extending file

This commit is contained in:
Jakob Unterwurzacher 2015-09-18 20:10:55 +02:00
parent 67fe4557e5
commit e84c1e3741
1 changed files with 8 additions and 3 deletions

View File

@ -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)