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

Function benchmarkStatelessEncoder

flate/writer_test.go:224–255  ·  view source on GitHub ↗
(b *testing.B, testfile, n int)

Source from the content-addressed store, hash-verified

222func BenchmarkEncodeTwain1024Win1e6(b *testing.B) { benchmarkEncoder(b, twain, oneK, 1e6) }
223
224func benchmarkStatelessEncoder(b *testing.B, testfile, n int) {
225 b.SetBytes(int64(n))
226 buf0, err := os.ReadFile(testfiles[testfile])
227 if err != nil {
228 b.Fatal(err)
229 }
230 if len(buf0) == 0 {
231 b.Fatalf("test file %q has no data", testfiles[testfile])
232 }
233 buf1 := make([]byte, n)
234 for i := 0; i < n; i += len(buf0) {
235 if len(buf0) > n-i {
236 buf0 = buf0[:n-i]
237 }
238 copy(buf1[i:], buf0)
239 }
240 buf0 = nil
241 runtime.GC()
242 b.ResetTimer()
243 b.ReportAllocs()
244 for i := 0; i < b.N; i++ {
245 w := NewStatelessWriter(io.Discard)
246 _, err = w.Write(buf1)
247 if err != nil {
248 b.Fatal(err)
249 }
250 err = w.Close()
251 if err != nil {
252 b.Fatal(err)
253 }
254 }
255}
256
257// A writer that fails after N writes.
258type errorWriter struct {

Callers 6

Calls 4

NewStatelessWriterFunction · 0.85
FatalMethod · 0.80
WriteMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…