diff options
author | Nigel Tao <nigeltao@golang.org> | 2020-06-13 12:28:08 +1000 |
---|---|---|
committer | Nigel Tao <nigeltao@golang.org> | 2020-06-14 12:41:37 +0000 |
commit | 97019105884ced2c4658f9763528e7f6983f8773 (patch) | |
tree | 1c808cd86d2de0b95a52d3461698b493ff6270db /src/image | |
parent | bd486c39bad4c9f90190ae58de8a592bb9a2aae9 (diff) | |
download | go-97019105884ced2c4658f9763528e7f6983f8773.tar.gz go-97019105884ced2c4658f9763528e7f6983f8773.zip |
image/gif: speed up initializing test image
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 <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/gif/writer_test.go | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/image/gif/writer_test.go b/src/image/gif/writer_test.go index b619961787..9b15c8d99d 100644 --- a/src/image/gif/writer_test.go +++ b/src/image/gif/writer_test.go @@ -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. @@ -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) |