Browse code

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 <josh.hawn@docker.com> (github: jlhawn)

Josh Hawn authored on 2014/12/04 03:35:20
Showing 1 changed files
... ...
@@ -486,10 +486,13 @@ func Benchmark9kTar(b *testing.B) {
486 486
 	n, err := io.Copy(buf, fh)
487 487
 	fh.Close()
488 488
 
489
+	reader := bytes.NewReader(buf.Bytes())
490
+
489 491
 	b.SetBytes(n)
490 492
 	b.ResetTimer()
491 493
 	for i := 0; i < b.N; i++ {
492
-		ts, err := NewTarSum(buf, true, Version0)
494
+		reader.Seek(0, 0)
495
+		ts, err := NewTarSum(reader, true, Version0)
493 496
 		if err != nil {
494 497
 			b.Error(err)
495 498
 			return
... ...
@@ -509,10 +512,13 @@ func Benchmark9kTarGzip(b *testing.B) {
509 509
 	n, err := io.Copy(buf, fh)
510 510
 	fh.Close()
511 511
 
512
+	reader := bytes.NewReader(buf.Bytes())
513
+
512 514
 	b.SetBytes(n)
513 515
 	b.ResetTimer()
514 516
 	for i := 0; i < b.N; i++ {
515
-		ts, err := NewTarSum(buf, false, Version0)
517
+		reader.Seek(0, 0)
518
+		ts, err := NewTarSum(reader, false, Version0)
516 519
 		if err != nil {
517 520
 			b.Error(err)
518 521
 			return