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))
for y := bo.Min.Y; y < bo.Max.Y; y++ {
for x := bo.Min.X; x < bo.Max.X; x++ {
cy := img.YOffset(x, y)
ci := img.COffset(x, y)
img.Y[cy] = uint8(rnd.Intn(256))
img.Cb[ci] = uint8(rnd.Intn(256))
img.Cr[ci] = uint8(rnd.Intn(256))
}
}
b.SetBytes(640 * 480 * 4)
b.StartTimer()
options := &Options{Quality: 90}
for i := 0; i < b.N; i++ {
Encode(ioutil.Discard, img, options)
}
}
What did you expect to see?
jpeg.Encode() of *image.YCbCr should be faster than for *image.RGBA
What did you see instead?
This is slow as jpeg.Encode() uses the generic image.At() which involves unnecessary ycbr->rgba->ycbcr conversions, and more importantly image.color allocations
The text was updated successfully, but these errors were encountered:
benchmark old ns/op new ns/op delta
BenchmarkEncodeYCbCr-4 43990846 24201148 -44.99%
benchmark old MB/s new MB/s speedup
BenchmarkEncodeYCbCr-4 20.95 38.08 1.82x
josharian
changed the title
jpeg encoding an *image.YCbCr is sub-optimal
image/jpeg: encoding an *image.YCbCr is sub-optimal
Jan 1, 2017
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?master
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
jpeg.Encode() of *image.YCbCr should be faster than for *image.RGBA
What did you see instead?
This is slow as jpeg.Encode() uses the generic image.At() which involves unnecessary ycbr->rgba->ycbcr conversions, and more importantly image.color allocations
The text was updated successfully, but these errors were encountered: