(b *testing.B)
| 7 | ) |
| 8 | |
| 9 | func BenchmarkZstdMemoryConsumption(b *testing.B) { |
| 10 | params := ZstdEncoderParams{Level: 9} |
| 11 | buf := make([]byte, 1024*1024) |
| 12 | for i := range buf { |
| 13 | buf[i] = byte((i / 256) + (i * 257)) |
| 14 | } |
| 15 | |
| 16 | b.Run("no_drain", func(b *testing.B) { |
| 17 | b.ReportAllocs() |
| 18 | for b.Loop() { |
| 19 | _, _ = zstdCompress(params, nil, buf) |
| 20 | } |
| 21 | }) |
| 22 | |
| 23 | // Drops the buffered encoder so we can measure cold-start allocation. |
| 24 | b.Run("with_drain", func(b *testing.B) { |
| 25 | b.ReportAllocs() |
| 26 | for b.Loop() { |
| 27 | _, _ = zstdCompress(params, nil, buf) |
| 28 | _ = getZstdEncoder(params) |
| 29 | } |
| 30 | }) |
| 31 | |
| 32 | // Concurrent encodes, which historically allocated a fresh encoder per |
| 33 | // batch for every concurrent caller beyond the first. RunParallel uses |
| 34 | // GOMAXPROCS goroutines by default; SetParallelism scales that ratio for |
| 35 | // hosts where exercising more concurrency than CPUs is interesting. |
| 36 | b.Run("concurrent", func(b *testing.B) { |
| 37 | b.ReportAllocs() |
| 38 | b.SetParallelism(2) |
| 39 | b.RunParallel(func(pb *testing.PB) { |
| 40 | for pb.Next() { |
| 41 | _, _ = zstdCompress(params, nil, buf) |
| 42 | } |
| 43 | }) |
| 44 | }) |
| 45 | } |
nothing calls this directly
no test coverage detected