|
|
@@ -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
|
|
|
}
|
|
|
}
|