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

Function BenchmarkRandom10MBEncoderFastest

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

Source from the content-addressed store, hash-verified

1242}
1243
1244func BenchmarkRandom10MBEncoderFastest(b *testing.B) {
1245 rng := rand.New(rand.NewSource(1))
1246 data := make([]byte, 10<<20)
1247 rng.Read(data)
1248 wantSize := int64(len(data))
1249 enc, _ := NewWriter(io.Discard, WithEncoderLevel(SpeedFastest))
1250 defer enc.Close()
1251 n, err := io.Copy(enc, bytes.NewBuffer(data))
1252 if err != nil {
1253 b.Fatal(err)
1254 }
1255 if n != wantSize {
1256 b.Fatal(n, "!=", wantSize)
1257 }
1258 b.ResetTimer()
1259 b.ReportAllocs()
1260 b.SetBytes(wantSize)
1261 for i := 0; i < b.N; i++ {
1262 enc.Reset(io.Discard)
1263 n, err := io.Copy(enc, bytes.NewBuffer(data))
1264 if err != nil {
1265 b.Fatal(err)
1266 }
1267 if n != wantSize {
1268 b.Fatal(n, "!=", wantSize)
1269 }
1270 }
1271}
1272
1273func BenchmarkRandomEncoderDefault(b *testing.B) {
1274 rng := rand.New(rand.NewSource(1))

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…