Browse Source

Add image and audio benchmarks.

Dmitry Chestnykh 14 years ago
parent
commit
6ca6c38639
2 changed files with 53 additions and 0 deletions
  1. 22 0
      audio_test.go
  2. 31 0
      image_test.go

+ 22 - 0
audio_test.go

@@ -0,0 +1,22 @@
+package captcha
+
+import "testing"
+
+func BenchmarkNewAudio(b *testing.B) {
+	b.StopTimer()
+	d := RandomDigits(DefaultLen)
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		NewAudio(d)
+	}
+}
+
+func BenchmarkAudioWriteTo(b *testing.B) {
+	b.StopTimer()
+	d := RandomDigits(DefaultLen)
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		a := NewAudio(d)
+		a.WriteTo(devNull{}) //TODO(dchest): use ioutil.Discard when its available
+	}
+}

+ 31 - 0
image_test.go

@@ -0,0 +1,31 @@
+package captcha
+
+import (
+	"os"
+	"testing"
+)
+
+type devNull struct{}
+
+func (devNull) Write(b []byte) (int, os.Error) {
+	return len(b), nil
+}
+
+func BenchmarkNewImage(b *testing.B) {
+	b.StopTimer()
+	d := RandomDigits(DefaultLen)
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		NewImage(d, StdWidth, StdHeight)
+	}
+}
+
+func BenchmarkImageWriteTo(b *testing.B) {
+	b.StopTimer()
+	d := RandomDigits(DefaultLen)
+	b.StartTimer()
+	for i := 0; i < b.N; i++ {
+		img := NewImage(d, StdWidth, StdHeight)
+		img.WriteTo(devNull{}) //TODO(dchest): use ioutil.Discard when its available
+	}
+}