]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip: add flate writing benchmark
authorBrad Fitzpatrick <bradfitz@golang.org>
Sun, 9 Feb 2014 21:56:47 +0000 (13:56 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 9 Feb 2014 21:56:47 +0000 (13:56 -0800)
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/60530049

src/pkg/archive/zip/writer_test.go

index 8b1c4dfd265f69fae24817ae803fd08719c3947b..4bfa87080906e1d8176de54947a0efea2e701dce 100644 (file)
@@ -125,3 +125,21 @@ func testReadFile(t *testing.T, f *File, wt *WriteTest) {
                t.Errorf("File contents %q, want %q", b, wt.Data)
        }
 }
+
+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++ {
+               buf.Reset()
+               zw := NewWriter(&buf)
+               for j := 0; j < 3; j++ {
+                       w, _ := zw.CreateHeader(&FileHeader{
+                               Name:   "foo",
+                               Method: Deflate,
+                       })
+                       w.Write(bigBuf)
+               }
+               zw.Close()
+       }
+}