apa102: simplify Draw() benchmark (#253)

pull/1/head
Ben Lazarus 8 years ago committed by M-A
parent a90b2edbb3
commit 82d2ba2f9b

@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"image" "image"
"image/color" "image/color"
"image/draw"
"io/ioutil" "io/ioutil"
"testing" "testing"
@ -708,29 +709,14 @@ func BenchmarkWriteColorfulVariation(b *testing.B) {
} }
} }
func fillImage(img image.Image, f genColor) { func benchmarkDraw(b *testing.B, o Opts, img draw.Image, f genColor) {
switch im := img.(type) { for x := 0; x < img.Bounds().Dx(); x++ {
case *image.NRGBA: for y := 0; y < img.Bounds().Dy(); y++ {
for x := 0; x < im.Bounds().Dx(); x++ { pix := f(x)
for y := 0; y < im.Bounds().Dy(); y++ { c := color.NRGBA{R: pix[0], G: pix[1], B: pix[2], A: 255}
pix := f(x) img.Set(x, y, c)
c := color.NRGBA{R: pix[0], G: pix[1], B: pix[2], A: 255}
im.Set(x, y, c)
}
}
case *image.RGBA:
for x := 0; x < im.Bounds().Dx(); x++ {
for y := 0; y < im.Bounds().Dy(); y++ {
pix := f(x)
c := color.NRGBA{R: pix[0], G: pix[1], B: pix[2], A: 255}
im.Set(x, y, c)
}
} }
} }
}
func benchmarkDraw(b *testing.B, o Opts, img image.Image, f genColor) {
fillImage(img, f)
o.NumPixels = img.Bounds().Max.X o.NumPixels = img.Bounds().Max.X
b.ReportAllocs() b.ReportAllocs()
d, _ := New(spitest.NewRecordRaw(ioutil.Discard), &o) d, _ := New(spitest.NewRecordRaw(ioutil.Discard), &o)

Loading…
Cancel
Save