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

Function benchmarkDecode

flate/reader_test.go:42–76  ·  view source on GitHub ↗
(b *testing.B, testfile, level, n int)

Source from the content-addressed store, hash-verified

40}
41
42func benchmarkDecode(b *testing.B, testfile, level, n int) {
43 b.ReportAllocs()
44 b.StopTimer()
45 b.SetBytes(int64(n))
46 buf0, err := os.ReadFile(testfiles[testfile])
47 if err != nil {
48 b.Fatal(err)
49 }
50 if len(buf0) == 0 {
51 b.Fatalf("test file %q has no data", testfiles[testfile])
52 }
53 compressed := new(bytes.Buffer)
54 w, err := NewWriter(compressed, level)
55 if err != nil {
56 b.Fatal(err)
57 }
58 for i := 0; i < n; i += len(buf0) {
59 if len(buf0) > n-i {
60 buf0 = buf0[:n-i]
61 }
62 io.Copy(w, bytes.NewReader(buf0))
63 }
64 w.Close()
65 buf1 := compressed.Bytes()
66 buf0, compressed, w = nil, nil, nil
67 r := NewReader(bytes.NewReader(buf1))
68 res := r.(Resetter)
69 runtime.GC()
70 b.StartTimer()
71
72 for i := 0; i < b.N; i++ {
73 _ = res.Reset(bytes.NewReader(buf1), nil)
74 _, _ = io.Copy(io.Discard, r)
75 }
76}
77
78// These short names are so that gofmt doesn't break the BenchmarkXxx function
79// bodies below over multiple lines.

Calls 7

CloseMethod · 0.95
FatalMethod · 0.80
CopyMethod · 0.80
NewWriterFunction · 0.70
NewReaderFunction · 0.70
BytesMethod · 0.65
ResetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…