all repos — captcha @ aef40a9ca4abd64a3a5181853583804d33d7d71b

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

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
commit

aef40a9ca4abd64a3a5181853583804d33d7d71b

parent

436e363f8439b0ac604f152748e2e13bbe575b53

2 files changed, 15 insertions(+), 5 deletions(-)

jump to
M audio_test.goaudio_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.goimage_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 } }