1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #9479 from jlhawn/tarsum_test_fix

Correct TarSum benchmarks: 9kTar and 9kTarGzip
This commit is contained in:
Alexander Morozov 2014-12-05 14:47:54 -08:00
commit 984b072a37

View file

@ -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),
@ -486,10 +487,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 +513,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