}
func BenchmarkEncode(b *testing.B) {
- b.StopTimer()
-
bo := image.Rect(0, 0, 640, 480)
rnd := rand.New(rand.NewSource(123))
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img, nil)
}
}
func BenchmarkQuantizedEncode(b *testing.B) {
- b.StopTimer()
img := image.NewRGBA(image.Rect(0, 0, 640, 480))
bo := img.Bounds()
rnd := rand.New(rand.NewSource(123))
}
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img, nil)
}
}
func BenchmarkEncodeRGBA(b *testing.B) {
- b.StopTimer()
img := image.NewRGBA(image.Rect(0, 0, 640, 480))
bo := img.Bounds()
rnd := rand.New(rand.NewSource(123))
}
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
options := &Options{Quality: 90}
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img, options)
}
func BenchmarkEncodeYCbCr(b *testing.B) {
- b.StopTimer()
img := image.NewYCbCr(image.Rect(0, 0, 640, 480), image.YCbCrSubsampleRatio420)
bo := img.Bounds()
rnd := rand.New(rand.NewSource(123))
}
}
b.SetBytes(640 * 480 * 3)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
options := &Options{Quality: 90}
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img, options)
}
func BenchmarkEncodeGray(b *testing.B) {
- b.StopTimer()
img := image.NewGray(image.Rect(0, 0, 640, 480))
b.SetBytes(640 * 480 * 1)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
}
}
func BenchmarkEncodeGrayWithBufferPool(b *testing.B) {
- b.StopTimer()
img := image.NewGray(image.Rect(0, 0, 640, 480))
e := Encoder{
BufferPool: &pool{},
}
b.SetBytes(640 * 480 * 1)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Encode(ioutil.Discard, img)
}
}
func BenchmarkEncodeNRGBOpaque(b *testing.B) {
- b.StopTimer()
img := image.NewNRGBA(image.Rect(0, 0, 640, 480))
// Set all pixels to 0xFF alpha to force opaque mode.
bo := img.Bounds()
b.Fatal("expected image to be opaque")
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
}
}
func BenchmarkEncodeNRGBA(b *testing.B) {
- b.StopTimer()
img := image.NewNRGBA(image.Rect(0, 0, 640, 480))
if img.Opaque() {
b.Fatal("expected image not to be opaque")
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
}
}
func BenchmarkEncodePaletted(b *testing.B) {
- b.StopTimer()
img := image.NewPaletted(image.Rect(0, 0, 640, 480), color.Palette{
color.RGBA{0, 0, 0, 255},
color.RGBA{255, 255, 255, 255},
})
b.SetBytes(640 * 480 * 1)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
}
}
func BenchmarkEncodeRGBOpaque(b *testing.B) {
- b.StopTimer()
img := image.NewRGBA(image.Rect(0, 0, 640, 480))
// Set all pixels to 0xFF alpha to force opaque mode.
bo := img.Bounds()
b.Fatal("expected image to be opaque")
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
}
}
func BenchmarkEncodeRGBA(b *testing.B) {
- b.StopTimer()
img := image.NewRGBA(image.Rect(0, 0, 640, 480))
if img.Opaque() {
b.Fatal("expected image not to be opaque")
}
b.SetBytes(640 * 480 * 4)
- b.StartTimer()
+ b.ReportAllocs()
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img)
}