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