Просмотр исходного кода

Report MB/s in audio and image benchmarks.

Also, audio benchmark uses the new ioutil.Discard.
Dmitry Chestnykh 14 лет назад
Родитель
Сommit
aef40a9ca4
2 измененных файлов с 15 добавлено и 5 удалено
  1. 6 2
      audio_test.go
  2. 9 3
      image_test.go

+ 6 - 2
audio_test.go

@@ -1,6 +1,9 @@
 package captcha
 
-import "testing"
+import (
+	"io/ioutil"
+	"testing"
+)
 
 func BenchmarkNewAudio(b *testing.B) {
 	b.StopTimer()
@@ -17,6 +20,7 @@ func BenchmarkAudioWriteTo(b *testing.B) {
 	b.StartTimer()
 	for i := 0; i < b.N; i++ {
 		a := NewAudio(d)
-		a.WriteTo(devNull{}) //TODO(dchest): use ioutil.Discard when its available
+		n, _ := a.WriteTo(ioutil.Discard)
+		b.SetBytes(n)
 	}
 }

+ 9 - 3
image_test.go

@@ -5,9 +5,12 @@ import (
 	"testing"
 )
 
-type devNull struct{}
+type byteCounter struct {
+	n int64
+}
 
-func (devNull) Write(b []byte) (int, os.Error) {
+func (bc *byteCounter) Write(b []byte) (int, os.Error) {
+	bc.n += int64(len(b))
 	return len(b), nil
 }
 
@@ -24,8 +27,11 @@ func BenchmarkImageWriteTo(b *testing.B) {
 	b.StopTimer()
 	d := RandomDigits(DefaultLen)
 	b.StartTimer()
+	counter := &byteCounter{}
 	for i := 0; i < b.N; i++ {
 		img := NewImage(d, StdWidth, StdHeight)
-		img.WriteTo(devNull{}) //TODO(dchest): use ioutil.Discard when its available
+		img.WriteTo(counter)
+		b.SetBytes(counter.n)
+		counter.n = 0
 	}
 }