]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip: parallelize benchmarks
authorBryan C. Mills <bcmills@google.com>
Fri, 10 Feb 2017 17:46:14 +0000 (12:46 -0500)
committerBryan Mills <bcmills@google.com>
Wed, 15 Mar 2017 18:26:51 +0000 (18:26 +0000)
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>
src/archive/zip/writer_test.go
src/archive/zip/zip_test.go

index 86841c755f160ee371976556d03b1506b7c271e2..84b1d9e06294e924bb100febce689e37eebaba1b 100644 (file)
@@ -181,12 +181,11 @@ func testReadFile(t *testing.T, f *File, wt *WriteTest) {
 }
 
 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",
@@ -195,11 +194,19 @@ func BenchmarkCompressedZipGarbage(b *testing.B) {
                        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)
+               }
+       })
 }
index 72d2b00089ccfcd8c9cbee20d7684f5ac298933d..18c2171ba6c15ba13937336c286e6857aaace10c 100644 (file)
@@ -681,6 +681,18 @@ func BenchmarkZip64Test(b *testing.B) {
        }
 }
 
+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}