Add image and audio benchmarks.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 01:19:56 +0200
2 files changed,
53 insertions(+),
0 deletions(-)
A
audio_test.go
@@ -0,0 +1,22 @@
+package captcha + +import "testing" + +func BenchmarkNewAudio(b *testing.B) { + b.StopTimer() + d := RandomDigits(DefaultLen) + b.StartTimer() + for i := 0; i < b.N; i++ { + NewAudio(d) + } +} + +func BenchmarkAudioWriteTo(b *testing.B) { + b.StopTimer() + 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 + } +}
A
image_test.go
@@ -0,0 +1,31 @@
+package captcha + +import ( + "os" + "testing" +) + +type devNull struct{} + +func (devNull) Write(b []byte) (int, os.Error) { + return len(b), nil +} + +func BenchmarkNewImage(b *testing.B) { + b.StopTimer() + d := RandomDigits(DefaultLen) + b.StartTimer() + for i := 0; i < b.N; i++ { + NewImage(d, StdWidth, StdHeight) + } +} + +func BenchmarkImageWriteTo(b *testing.B) { + b.StopTimer() + d := RandomDigits(DefaultLen) + b.StartTimer() + for i := 0; i < b.N; i++ { + img := NewImage(d, StdWidth, StdHeight) + img.WriteTo(devNull{}) //TODO(dchest): use ioutil.Discard when its available + } +}