MCPcopy Index your code
hub / github.com/klauspost/compress / BenchmarkRandomEncoderDefault

Function BenchmarkRandomEncoderDefault

zstd/encoder_test.go:1273–1300  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1271}
1272
1273func BenchmarkRandomEncoderDefault(b *testing.B) {
1274 rng := rand.New(rand.NewSource(1))
1275 data := make([]byte, 10<<20)
1276 rng.Read(data)
1277 wantSize := int64(len(data))
1278 enc, _ := NewWriter(io.Discard, WithEncoderLevel(SpeedDefault))
1279 defer enc.Close()
1280 n, err := io.Copy(enc, bytes.NewBuffer(data))
1281 if err != nil {
1282 b.Fatal(err)
1283 }
1284 if n != wantSize {
1285 b.Fatal(n, "!=", wantSize)
1286 }
1287 b.ResetTimer()
1288 b.ReportAllocs()
1289 b.SetBytes(wantSize)
1290 for i := 0; i < b.N; i++ {
1291 enc.Reset(io.Discard)
1292 n, err := io.Copy(enc, bytes.NewBuffer(data))
1293 if err != nil {
1294 b.Fatal(err)
1295 }
1296 if n != wantSize {
1297 b.Fatal(n, "!=", wantSize)
1298 }
1299 }
1300}

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.95
ResetMethod · 0.95
WithEncoderLevelFunction · 0.85
CopyMethod · 0.80
FatalMethod · 0.80
NewWriterFunction · 0.70
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…