all repos — captcha @ f14d4a9979825b6bc693f15cc3fc97b26145562b

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

image_test.go (view raw)

 1package captcha
 2
 3import (
 4	"os"
 5	"testing"
 6)
 7
 8type byteCounter struct {
 9	n int64
10}
11
12func (bc *byteCounter) Write(b []byte) (int, os.Error) {
13	bc.n += int64(len(b))
14	return len(b), nil
15}
16
17func BenchmarkNewImage(b *testing.B) {
18	b.StopTimer()
19	d := RandomDigits(DefaultLen)
20	b.StartTimer()
21	for i := 0; i < b.N; i++ {
22		NewImage(d, StdWidth, StdHeight)
23	}
24}
25
26func BenchmarkImageWriteTo(b *testing.B) {
27	b.StopTimer()
28	d := RandomDigits(DefaultLen)
29	b.StartTimer()
30	counter := &byteCounter{}
31	for i := 0; i < b.N; i++ {
32		img := NewImage(d, StdWidth, StdHeight)
33		img.WriteTo(counter)
34		b.SetBytes(counter.n)
35		counter.n = 0
36	}
37}