Report MB/s in audio and image benchmarks. Also, audio benchmark uses the new ioutil.Discard.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 14:58:53 +0200
2 files changed,
15 insertions(+),
5 deletions(-)
M
audio_test.go
→
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 @@ d := RandomDigits(DefaultLen)
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) } }
M
image_test.go
→
image_test.go
@@ -5,9 +5,12 @@ "os"
"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 } }