image_test.go (view raw)
1// Copyright 2011 Dmitry Chestnykh. All rights reserved.
2// Use of this source code is governed by a MIT-style
3// license that can be found in the LICENSE file.
4
5package captcha
6
7import "testing"
8
9type byteCounter struct {
10 n int64
11}
12
13func (bc *byteCounter) Write(b []byte) (int, error) {
14 bc.n += int64(len(b))
15 return len(b), nil
16}
17
18func BenchmarkNewImage(b *testing.B) {
19 b.StopTimer()
20 d := RandomDigits(DefaultLen)
21 b.StartTimer()
22 for i := 0; i < b.N; i++ {
23 NewImage(d, StdWidth, StdHeight)
24 }
25}
26
27func BenchmarkImageWriteTo(b *testing.B) {
28 b.StopTimer()
29 d := RandomDigits(DefaultLen)
30 b.StartTimer()
31 counter := &byteCounter{}
32 for i := 0; i < b.N; i++ {
33 img := NewImage(d, StdWidth, StdHeight)
34 img.WriteTo(counter)
35 b.SetBytes(counter.n)
36 counter.n = 0
37 }
38}