image_test.go (view raw)
1package captcha
2
3import (
4 "os"
5 "testing"
6)
7
8type devNull struct{}
9
10func (devNull) Write(b []byte) (int, os.Error) {
11 return len(b), nil
12}
13
14func BenchmarkNewImage(b *testing.B) {
15 b.StopTimer()
16 d := RandomDigits(DefaultLen)
17 b.StartTimer()
18 for i := 0; i < b.N; i++ {
19 NewImage(d, StdWidth, StdHeight)
20 }
21}
22
23func BenchmarkImageWriteTo(b *testing.B) {
24 b.StopTimer()
25 d := RandomDigits(DefaultLen)
26 b.StartTimer()
27 for i := 0; i < b.N; i++ {
28 img := NewImage(d, StdWidth, StdHeight)
29 img.WriteTo(devNull{}) //TODO(dchest): use ioutil.Discard when its available
30 }
31}