Skip to content

Commit a1ebe3c

Browse files
nixprimegvisor-bot
authored andcommitted
Measure decompression time in compressio decompression benchmarks.
IIUC, Go sets testing.b.N by running benchmarks repeatedly with increasing values of b.N until a "reasonable" benchmark run time is achieved. Before this CL, decompression benchmarks measure the time to perform *compression* once while scaling the number of decompressions with b.N, making the Go-observed benchmark time independent of b.N and causing Go to increase b.N to unpredictable and unreasonable amounts: ``` BenchmarkDecompressNoHash1M pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 821.474577ms, ratio 0.75, decompression time 1.161417487s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 526.175362ms, ratio 0.75, decompression time 1.937750371s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 767.402422ms, ratio 0.75, decompression time 2.156883246s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 779.148676ms, ratio 0.75, decompression time 2.396898003s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 577.573005ms, ratio 0.75, decompression time 3.266100928s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 524.66472ms, ratio 0.75, decompression time 5.922212382s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 714.897653ms, ratio 0.75, decompression time 13.105200153s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 768.187436ms, ratio 0.75, decompression time 19.574360494s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 625.937757ms, ratio 0.75, decompression time 30.097482785s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 767.470509ms, ratio 0.75, decompression time 56.130162322s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 527.026934ms, ratio 0.75, decompression time 1m36.04235679s pkg/compressio/compressio_test.go:152: compress=false, hash=false, len(data)=838860800, blockSize=1048576: compression time 943.736532ms, ratio 0.75, decompression time 3m15.294992151s panic: SIGTERM ``` PiperOrigin-RevId: 615249406
1 parent 3b314aa commit a1ebe3c

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

pkg/compressio/compressio_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,31 +219,30 @@ func benchmark(b *testing.B, compress bool, hash bool, blockSize uint32) {
219219
b.StopTimer()
220220
b.SetBytes(benchDataSize)
221221
data := initTest(b, benchDataSize)
222-
compIters := b.N
223-
decompIters := b.N
224-
if compress {
225-
decompIters = 0
226-
} else {
227-
compIters = 0
228-
}
229222
key := hashKey
230223
if !hash {
231224
key = nil
232225
}
233-
doTest(b, testOpts{
234-
Name: fmt.Sprintf("compress=%t, hash=%t, len(data)=%d, blockSize=%d", compress, hash, len(data), blockSize),
235-
Data: data,
236-
PreCompress: b.StartTimer,
237-
PostCompress: b.StopTimer,
226+
opts := testOpts{
227+
Name: fmt.Sprintf("compress=%t, hash=%t, len(data)=%d, blockSize=%d", compress, hash, len(data), blockSize),
228+
Data: data,
238229
NewWriter: func(b *bytes.Buffer) (io.Writer, error) {
239230
return NewWriter(b, key, blockSize, flate.BestSpeed)
240231
},
241232
NewReader: func(b *bytes.Buffer) (io.Reader, error) {
242233
return NewReader(b, key)
243234
},
244-
CompressIters: compIters,
245-
DecompressIters: decompIters,
246-
})
235+
}
236+
if compress {
237+
opts.PreCompress = b.StartTimer
238+
opts.PostCompress = b.StopTimer
239+
opts.CompressIters = b.N
240+
} else {
241+
opts.PreDecompress = b.StartTimer
242+
opts.PostDecompress = b.StopTimer
243+
opts.DecompressIters = b.N
244+
}
245+
doTest(b, opts)
247246
}
248247

249248
func BenchmarkCompressNoHash64K(b *testing.B) {

0 commit comments

Comments
 (0)