all repos — captcha @ 6ca6c38639ef00c333b421486ce16ce946a31a24

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Add image and audio benchmarks.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 01:19:56 +0200
commit

6ca6c38639ef00c333b421486ce16ce946a31a24

parent

d4eb7a3cfce5fa8b432058a8cecf2e024d55edd8

2 files changed, 53 insertions(+), 0 deletions(-)

jump to
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 + } +}