mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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
This commit is contained in:
@@ -219,31 +219,30 @@ func benchmark(b *testing.B, compress bool, hash bool, blockSize uint32) {
|
||||
b.StopTimer()
|
||||
b.SetBytes(benchDataSize)
|
||||
data := initTest(b, benchDataSize)
|
||||
compIters := b.N
|
||||
decompIters := b.N
|
||||
if compress {
|
||||
decompIters = 0
|
||||
} else {
|
||||
compIters = 0
|
||||
}
|
||||
key := hashKey
|
||||
if !hash {
|
||||
key = nil
|
||||
}
|
||||
doTest(b, testOpts{
|
||||
Name: fmt.Sprintf("compress=%t, hash=%t, len(data)=%d, blockSize=%d", compress, hash, len(data), blockSize),
|
||||
Data: data,
|
||||
PreCompress: b.StartTimer,
|
||||
PostCompress: b.StopTimer,
|
||||
opts := testOpts{
|
||||
Name: fmt.Sprintf("compress=%t, hash=%t, len(data)=%d, blockSize=%d", compress, hash, len(data), blockSize),
|
||||
Data: data,
|
||||
NewWriter: func(b *bytes.Buffer) (io.Writer, error) {
|
||||
return NewWriter(b, key, blockSize, flate.BestSpeed)
|
||||
},
|
||||
NewReader: func(b *bytes.Buffer) (io.Reader, error) {
|
||||
return NewReader(b, key)
|
||||
},
|
||||
CompressIters: compIters,
|
||||
DecompressIters: decompIters,
|
||||
})
|
||||
}
|
||||
if compress {
|
||||
opts.PreCompress = b.StartTimer
|
||||
opts.PostCompress = b.StopTimer
|
||||
opts.CompressIters = b.N
|
||||
} else {
|
||||
opts.PreDecompress = b.StartTimer
|
||||
opts.PostDecompress = b.StopTimer
|
||||
opts.DecompressIters = b.N
|
||||
}
|
||||
doTest(b, opts)
|
||||
}
|
||||
|
||||
func BenchmarkCompressNoHash64K(b *testing.B) {
|
||||
|
||||
Reference in New Issue
Block a user