image_test.go 570 B

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