all repos — captcha @ 9e952142169c3cd6268c6482a3a61c121536aca2

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

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	id := randomId()
22	b.StartTimer()
23	for i := 0; i < b.N; i++ {
24		NewImage(id, d, StdWidth, StdHeight)
25	}
26}
27
28func BenchmarkImageWriteTo(b *testing.B) {
29	b.StopTimer()
30	d := RandomDigits(DefaultLen)
31	id := randomId()
32	b.StartTimer()
33	counter := &byteCounter{}
34	for i := 0; i < b.N; i++ {
35		img := NewImage(id, d, StdWidth, StdHeight)
36		img.WriteTo(counter)
37		b.SetBytes(counter.n)
38		counter.n = 0
39	}
40}