MCPcopy
hub / github.com/klauspost/compress / BenchmarkDecoder_DecoderReset

Function BenchmarkDecoder_DecoderReset

zstd/decoder_test.go:1281–1338  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1279}
1280
1281func BenchmarkDecoder_DecoderReset(b *testing.B) {
1282 zr := testCreateZipReader("testdata/benchdecoder.zip", b)
1283 dec, err := NewReader(nil, WithDecodeBuffersBelow(0))
1284 if err != nil {
1285 b.Fatal(err)
1286 return
1287 }
1288 defer dec.Close()
1289 bench := func(name string, b *testing.B, opts []DOption, in, want []byte) {
1290 b.Helper()
1291 buf := newBytesReader(in)
1292 dec, err := NewReader(nil, opts...)
1293 if err != nil {
1294 b.Fatal(err)
1295 return
1296 }
1297 defer dec.Close()
1298 b.Run(name, func(b *testing.B) {
1299 b.SetBytes(1)
1300 b.ReportAllocs()
1301 b.ResetTimer()
1302 for i := 0; i < b.N; i++ {
1303 buf.Reset(in)
1304 err = dec.Reset(buf)
1305 if err != nil {
1306 b.Fatal(err)
1307 }
1308 }
1309 })
1310 }
1311 for _, tt := range zr.File {
1312 if !strings.HasSuffix(tt.Name, ".zst") {
1313 continue
1314 }
1315 b.Run(tt.Name, func(b *testing.B) {
1316 r, err := tt.Open()
1317 if err != nil {
1318 b.Fatal(err)
1319 }
1320 defer r.Close()
1321 in, err := io.ReadAll(r)
1322 if err != nil {
1323 b.Fatal(err)
1324 }
1325
1326 got, err := dec.DecodeAll(in, nil)
1327 if err != nil {
1328 b.Fatal(err)
1329 }
1330 // Disable buffers:
1331 bench("stream", b, []DOption{WithDecodeBuffersBelow(0)}, in, got)
1332 bench("stream-single", b, []DOption{WithDecodeBuffersBelow(0), WithDecoderConcurrency(1)}, in, got)
1333 // Force buffers:
1334 bench("buffer", b, []DOption{WithDecodeBuffersBelow(1 << 30)}, in, got)
1335 bench("buffer-single", b, []DOption{WithDecodeBuffersBelow(1 << 30), WithDecoderConcurrency(1)}, in, got)
1336 })
1337 }
1338}

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
ResetMethod · 0.95
testCreateZipReaderFunction · 0.85
WithDecodeBuffersBelowFunction · 0.85
newBytesReaderFunction · 0.85
WithDecoderConcurrencyFunction · 0.85
FatalMethod · 0.80
DecodeAllMethod · 0.80
NewReaderFunction · 0.70
ResetMethod · 0.65
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…