image_test.go 627 B

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