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

Function BenchmarkDecoder_DecoderNewNoRead

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

Source from the content-addressed store, hash-verified

1361}
1362
1363func BenchmarkDecoder_DecoderNewNoRead(b *testing.B) {
1364 zr := testCreateZipReader("testdata/benchdecoder.zip", b)
1365 dec, err := NewReader(nil)
1366 if err != nil {
1367 b.Fatal(err)
1368 return
1369 }
1370 defer dec.Close()
1371
1372 bench := func(name string, b *testing.B, opts []DOption, in, want []byte) {
1373 b.Helper()
1374 b.Run(name, func(b *testing.B) {
1375 buf := newBytesReader(in)
1376 b.SetBytes(1)
1377 b.ReportAllocs()
1378 b.ResetTimer()
1379 for i := 0; i < b.N; i++ {
1380 buf.Reset(in)
1381 dec, err := NewReader(buf, opts...)
1382 if err != nil {
1383 b.Fatal(err)
1384 return
1385 }
1386 dec.Close()
1387 }
1388 })
1389 }
1390 for _, tt := range zr.File {
1391 if !strings.HasSuffix(tt.Name, ".zst") {
1392 continue
1393 }
1394 b.Run(tt.Name, func(b *testing.B) {
1395 r, err := tt.Open()
1396 if err != nil {
1397 b.Fatal(err)
1398 }
1399 defer r.Close()
1400 in, err := io.ReadAll(r)
1401 if err != nil {
1402 b.Fatal(err)
1403 }
1404
1405 got, err := dec.DecodeAll(in, nil)
1406 if err != nil {
1407 b.Fatal(err)
1408 }
1409 // Disable buffers:
1410 bench("stream", b, []DOption{WithDecodeBuffersBelow(0)}, in, got)
1411 bench("stream-single", b, []DOption{WithDecodeBuffersBelow(0), WithDecoderConcurrency(1)}, in, got)
1412 // Force buffers:
1413 bench("buffer", b, []DOption{WithDecodeBuffersBelow(1 << 30)}, in, got)
1414 bench("buffer-single", b, []DOption{WithDecodeBuffersBelow(1 << 30), WithDecoderConcurrency(1)}, in, got)
1415 })
1416 }
1417}
1418
1419func BenchmarkDecoder_DecoderNewSomeRead(b *testing.B) {
1420 var buf [1 << 20]byte

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
testCreateZipReaderFunction · 0.85
newBytesReaderFunction · 0.85
WithDecodeBuffersBelowFunction · 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…