Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
apa102: simplify Draw() benchmark (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlazarus authored and maruel committed Jul 14, 2018
1 parent 2a8252b commit 40fa1c4
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions devices/apa102/apa102_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"image"
"image/color"
"image/draw"
"io/ioutil"
"testing"

Expand Down Expand Up @@ -708,29 +709,14 @@ func BenchmarkWriteColorfulVariation(b *testing.B) {
}
}

func fillImage(img image.Image, f genColor) {
switch im := img.(type) {
case *image.NRGBA:
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)
}
}
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 draw.Image, f genColor) {
for x := 0; x < img.Bounds().Dx(); x++ {
for y := 0; y < img.Bounds().Dy(); y++ {
pix := f(x)
c := color.NRGBA{R: pix[0], G: pix[1], B: pix[2], A: 255}
img.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
b.ReportAllocs()
d, _ := New(spitest.NewRecordRaw(ioutil.Discard), &o)
Expand Down

0 comments on commit 40fa1c4

Please sign in to comment.