Skip to content

Commit

Permalink
image/gif: speed up initializing test image
Browse files Browse the repository at this point in the history
The benchmark throughput numbers don't change, but the set-up time (the
time taken before the b.ResetTimer() call) drops from 460ms to 4ms.

Change-Id: I5a6756643dff6127f6d902455d83459c084834fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/237757
Reviewed-by: Rob Pike <[email protected]>
Run-TryBot: Rob Pike <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
nigeltao committed Jun 14, 2020
1 parent bd486c3 commit 9701910
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/image/gif/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ func TestEncodeWrappedImage(t *testing.T) {
}

func BenchmarkEncode(b *testing.B) {
bo := image.Rect(0, 0, 640, 480)
rnd := rand.New(rand.NewSource(123))

// Restrict to a 256-color paletted image to avoid quantization path.
Expand All @@ -671,10 +670,8 @@ func BenchmarkEncode(b *testing.B) {
}
}
img := image.NewPaletted(image.Rect(0, 0, 640, 480), palette)
for y := bo.Min.Y; y < bo.Max.Y; y++ {
for x := bo.Min.X; x < bo.Max.X; x++ {
img.Set(x, y, palette[rnd.Intn(256)])
}
for i := range img.Pix {
img.Pix[i] = uint8(rnd.Intn(256))
}

b.SetBytes(640 * 480 * 4)
Expand Down

0 comments on commit 9701910

Please sign in to comment.