Skip to content

Commit

Permalink
Moved resampler creation and closing out of the benchmark loop
Browse files Browse the repository at this point in the history
  • Loading branch information
zaf committed Apr 19, 2018
1 parent 814040a commit d3790e3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions resample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,23 @@ func BenchmarkResampling(b *testing.B) {
if err != nil {
b.Fatalf("Failed to read test data: %s\n", err)
}
res, err := New(ioutil.Discard, bd.inRate, bd.outRate, bd.channels, bd.format, bd.quality)
if err != nil {
b.Fatalf("Failed to create Writer: %s\n", err)
}
b.SetBytes(int64(len(rawData[44:])))
b.ResetTimer()
for i := 0; i < b.N; i++ {
res, err := New(ioutil.Discard, bd.inRate, bd.outRate, bd.channels, bd.format, bd.quality)
if err != nil {
b.Fatalf("Failed to create Writer: %s\n", err)
}
_, err = res.Write(rawData[44:])
res.Close()
if err != nil {
b.Fatalf("Encoding failed: %s\n", err)
}
}
b.StopTimer()
res.Close()
if err != nil {
b.Fatalf("Failed to close the resampler: %s\n", err)
}
})
}
}

0 comments on commit d3790e3

Please sign in to comment.