From 985d3bd404c1a87dbff2d43ac7be64bd2c32afb4 Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Wed, 3 Dec 2014 10:35:20 -0800 Subject: [PATCH 1/2] Correct TarSum benchmarks: 9kTar and 9kTarGzip These two cases did not actually read the same content with each iteration of the benchmark. After the first read, the buffer was consumed. This patch corrects this by using a bytes.Reader and seeking to the beginning of the buffer at the beginning of each iteration. Unfortunately, this benchmark was not actually as fast as we believed. But the new results do bring its results closer to those of the other benchmarks. Docker-DCO-1.1-Signed-off-by: Josh Hawn (github: jlhawn) --- tarsum/tarsum_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tarsum/tarsum_test.go b/tarsum/tarsum_test.go index 41e1b9b..4e1f30e 100644 --- a/tarsum/tarsum_test.go +++ b/tarsum/tarsum_test.go @@ -486,10 +486,13 @@ func Benchmark9kTar(b *testing.B) { n, err := io.Copy(buf, fh) fh.Close() + reader := bytes.NewReader(buf.Bytes()) + b.SetBytes(n) b.ResetTimer() for i := 0; i < b.N; i++ { - ts, err := NewTarSum(buf, true, Version0) + reader.Seek(0, 0) + ts, err := NewTarSum(reader, true, Version0) if err != nil { b.Error(err) return @@ -509,10 +512,13 @@ func Benchmark9kTarGzip(b *testing.B) { n, err := io.Copy(buf, fh) fh.Close() + reader := bytes.NewReader(buf.Bytes()) + b.SetBytes(n) b.ResetTimer() for i := 0; i < b.N; i++ { - ts, err := NewTarSum(buf, false, Version0) + reader.Seek(0, 0) + ts, err := NewTarSum(reader, false, Version0) if err != nil { b.Error(err) return From d98b6f38ba9faca24d62ba578f282ae80060e545 Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Wed, 3 Dec 2014 22:23:31 -0800 Subject: [PATCH 2/2] Correctly close generated benchmark archives Another update to TarSum tests, this patch fixes an issue where the benchmarks were generating archives incorrectly by not closing the tarWriter. Docker-DCO-1.1-Signed-off-by: Josh Hawn (github: jlhawn) --- tarsum/tarsum_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tarsum/tarsum_test.go b/tarsum/tarsum_test.go index 4e1f30e..26f12cc 100644 --- a/tarsum/tarsum_test.go +++ b/tarsum/tarsum_test.go @@ -132,6 +132,7 @@ func sizedTar(opts sizedOptions) io.Reader { fh = bytes.NewBuffer([]byte{}) } tarW := tar.NewWriter(fh) + defer tarW.Close() for i := int64(0); i < opts.num; i++ { err := tarW.WriteHeader(&tar.Header{ Name: fmt.Sprintf("/testdata%d", i),