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

Function BenchmarkDecoder_DecoderNewSomeRead

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

Source from the content-addressed store, hash-verified

1417}
1418
1419func BenchmarkDecoder_DecoderNewSomeRead(b *testing.B) {
1420 var buf [1 << 20]byte
1421 bench := func(name string, b *testing.B, opts []DOption, in *os.File) {
1422 b.Helper()
1423 b.Run(name, func(b *testing.B) {
1424 //b.ReportAllocs()
1425 b.ResetTimer()
1426 var heapTotal int64
1427 var m runtime.MemStats
1428 for i := 0; i < b.N; i++ {
1429 runtime.GC()
1430 runtime.ReadMemStats(&m)
1431 heapTotal -= int64(m.HeapInuse)
1432 _, err := in.Seek(io.SeekStart, 0)
1433 if err != nil {
1434 b.Fatal(err)
1435 }
1436
1437 dec, err := NewReader(in, opts...)
1438 if err != nil {
1439 b.Fatal(err)
1440 }
1441 // Read 16 MB
1442 _, err = io.CopyBuffer(io.Discard, io.LimitReader(dec, 16<<20), buf[:])
1443 if err != nil {
1444 b.Fatal(err)
1445 }
1446 runtime.GC()
1447 runtime.ReadMemStats(&m)
1448 heapTotal += int64(m.HeapInuse)
1449
1450 dec.Close()
1451 }
1452 b.ReportMetric(float64(heapTotal)/float64(b.N), "b/op")
1453 })
1454 }
1455 files := []string{"testdata/000002.map.win32K.zst", "testdata/000002.map.win1MB.zst", "testdata/000002.map.win8MB.zst"}
1456 for _, file := range files {
1457 if !strings.HasSuffix(file, ".zst") {
1458 continue
1459 }
1460 r, err := os.Open(file)
1461 if err != nil {
1462 b.Fatal(err)
1463 }
1464 defer r.Close()
1465
1466 b.Run(file, func(b *testing.B) {
1467 bench("stream-single", b, []DOption{WithDecodeBuffersBelow(0), WithDecoderConcurrency(1)}, r)
1468 bench("stream-single-himem", b, []DOption{WithDecodeBuffersBelow(0), WithDecoderConcurrency(1), WithDecoderLowmem(false)}, r)
1469 })
1470 }
1471}
1472
1473func BenchmarkDecoder_DecodeAll(b *testing.B) {
1474 zr := testCreateZipReader("testdata/benchdecoder.zip", b)

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
WithDecodeBuffersBelowFunction · 0.85
WithDecoderConcurrencyFunction · 0.85
WithDecoderLowmemFunction · 0.85
FatalMethod · 0.80
NewReaderFunction · 0.70
CloseMethod · 0.65
SeekMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…