Skip to content

Commit

Permalink
Merge pull request #35 from nirs/fix-discard
Browse files Browse the repository at this point in the history
Use our own Discard for testing
  • Loading branch information
AkihiroSuda authored Oct 20, 2024
2 parents 5641962 + 5512113 commit b119fa3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion qcow2reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func benchmarkRead(b *testing.B, filename string) {
defer img.Close()
buf := make([]byte, 1*MiB)
reader := io.NewSectionReader(img, 0, img.Size())
n, err := io.CopyBuffer(io.Discard, reader, buf)
n, err := io.CopyBuffer(Discard, reader, buf)

b.StopTimer()

Expand All @@ -141,6 +141,17 @@ func benchmarkRead(b *testing.B, filename string) {
}
}

// We cannot use io.Discard since it implements ReadFrom using small buffers
// size (8192), confusing our test results. Reads smaller than cluster size (64
// KiB) are extremely inefficient with compressed clusters.
type discard struct{}

func (discard) Write(p []byte) (int, error) {
return len(p), nil
}

var Discard = discard{}

func resetBenchmark(b *testing.B, size int64) {
b.StopTimer()
b.ResetTimer()
Expand Down

0 comments on commit b119fa3

Please sign in to comment.