From: Josh Bleecher Snyder Date: Mon, 11 Apr 2016 18:54:07 +0000 (-0700) Subject: image/color: add YCbCrToRGB benchmark X-Git-Tag: go1.7beta1~768 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7166dfe0c11bd25b962d7f691ea1be857842dfbf;p=gostls13.git image/color: add YCbCrToRGB benchmark Change-Id: I9ba76d5b0861a901415fdceccaf2f5caa2facb7f Reviewed-on: https://go-review.googlesource.com/21837 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Brad Fitzpatrick --- diff --git a/src/image/color/ycbcr_test.go b/src/image/color/ycbcr_test.go index f5e7cbf335..1b110691a2 100644 --- a/src/image/color/ycbcr_test.go +++ b/src/image/color/ycbcr_test.go @@ -171,3 +171,26 @@ func TestPalette(t *testing.T) { t.Errorf("got %v, want %v", got, want) } } + +var sinkr, sinkg, sinkb uint8 + +func BenchmarkYCbCrToRGB(b *testing.B) { + // YCbCrToRGB does saturating arithmetic. + // Low, middle, and high values can take + // different paths through the generated code. + b.Run("0", func(b *testing.B) { + for i := 0; i < b.N; i++ { + sinkr, sinkg, sinkb = YCbCrToRGB(0, 0, 0) + } + }) + b.Run("128", func(b *testing.B) { + for i := 0; i < b.N; i++ { + sinkr, sinkg, sinkb = YCbCrToRGB(128, 128, 128) + } + }) + b.Run("255", func(b *testing.B) { + for i := 0; i < b.N; i++ { + sinkr, sinkg, sinkb = YCbCrToRGB(255, 255, 255) + } + }) +}