Add subbenchmarks for BenchmarkZip64Test with different sizes to tease
apart construction costs vs. steady-state throughput.
Results remain comparable with the non-parallel version with -cpu=1:
benchmark old ns/op new ns/op delta
BenchmarkCompressedZipGarbage
26832835 27506953 +2.51%
BenchmarkCompressedZipGarbage-6
27172377 4321534 -84.10%
BenchmarkZip64Test
196758732 197765510 +0.51%
BenchmarkZip64Test-6
193850605 192625458 -0.63%
benchmark old allocs new allocs delta
BenchmarkCompressedZipGarbage 44 44 +0.00%
BenchmarkCompressedZipGarbage-6 44 44 +0.00%
benchmark old bytes new bytes delta
BenchmarkCompressedZipGarbage 5592 5664 +1.29%
BenchmarkCompressedZipGarbage-6 5592 21946 +292.45%
updates #18177
Change-Id: Icfa359d9b1a8df5e085dacc07d2b9221b284764c
Reviewed-on: https://go-review.googlesource.com/36719
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
}
func BenchmarkCompressedZipGarbage(b *testing.B) {
- b.ReportAllocs()
- var buf bytes.Buffer
bigBuf := bytes.Repeat([]byte("a"), 1<<20)
- for i := 0; i <= b.N; i++ {
+
+ runOnce := func(buf *bytes.Buffer) {
buf.Reset()
- zw := NewWriter(&buf)
+ zw := NewWriter(buf)
for j := 0; j < 3; j++ {
w, _ := zw.CreateHeader(&FileHeader{
Name: "foo",
w.Write(bigBuf)
}
zw.Close()
- if i == 0 {
- // Reset the timer after the first time through.
- // This effectively discards the very large initial flate setup cost,
- // as well as the initialization of bigBuf.
- b.ResetTimer()
- }
}
+
+ b.ReportAllocs()
+ // Run once and then reset the timer.
+ // This effectively discards the very large initial flate setup cost,
+ // as well as the initialization of bigBuf.
+ runOnce(&bytes.Buffer{})
+ b.ResetTimer()
+
+ b.RunParallel(func(pb *testing.PB) {
+ var buf bytes.Buffer
+ for pb.Next() {
+ runOnce(&buf)
+ }
+ })
}
}
}
+func BenchmarkZip64TestSizes(b *testing.B) {
+ for _, size := range []int64{1 << 12, 1 << 20, 1 << 26} {
+ b.Run(fmt.Sprint(size), func(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ testZip64(b, size)
+ }
+ })
+ })
+ }
+}
+
func TestSuffixSaver(t *testing.T) {
const keep = 10
ss := &suffixSaver{keep: keep}