Add four_byte_interp benches.
Desktop:
running bench [640 480] four_byte_interp_slow_256 NONRENDERING: cmsecs = 6.18
running bench [640 480] four_byte_interp_slow_255 NONRENDERING: cmsecs = 6.83
running bench [640 480] four_byte_interp_fast_256 NONRENDERING: cmsecs = 5.02
running bench [640 480] four_byte_interp_fast_255 NONRENDERING: cmsecs = 5.88
N5:
running bench [640 480] four_byte_interp_slow_256 NONRENDERING: cmsecs = 22.84
running bench [640 480] four_byte_interp_slow_255 NONRENDERING: cmsecs = 25.11
running bench [640 480] four_byte_interp_fast_256 NONRENDERING: cmsecs = 18.89
running bench [640 480] four_byte_interp_fast_255 NONRENDERING: cmsecs = 22.32
BUG=
R=reed@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/93933003
git-svn-id: http://skia.googlecode.com/svn/trunk@12444 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/ColorPrivBench.cpp b/bench/ColorPrivBench.cpp
new file mode 100644
index 0000000..3143ef4
--- /dev/null
+++ b/bench/ColorPrivBench.cpp
@@ -0,0 +1,56 @@
+#include "SkBenchmark.h"
+#include "SkColorPriv.h"
+#include "SkRandom.h"
+#include "SkString.h"
+
+template <bool kFast, bool kScale>
+class FourByteInterpBench : public SkBenchmark {
+public:
+ FourByteInterpBench() {
+ fName.set("four_byte_interp");
+ fName.append(kFast ? "_fast" : "_slow");
+ fName.append(kScale ? "_255" : "_256");
+
+ // We'll exhaustively test all scales instead of using random numbers.
+ for (int i = 0; i <= 256; i++) {
+ fScales[i] = i;
+ }
+ if (kScale) fScales[256] = 255; // We'll just do 255 twice if we're limited to [0,255].
+ }
+
+ virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
+ return backend == kNonRendering_Backend;
+ }
+
+ virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); }
+
+ virtual void onDraw(SkCanvas*) SK_OVERRIDE {
+ const SkPMColor src = 0xAB998877, dst = 0x66334455;
+ volatile SkPMColor junk = 0;
+ for (int i = 0; i < 10*this->getLoops(); ++i) {
+ for (size_t j = 0; j <= SK_ARRAY_COUNT(fScales); j++) {
+ const unsigned scale = fScales[j];
+ if (kFast && kScale) {
+ junk ^= SkFastFourByteInterp(src, dst, scale);
+ } else if (kFast) {
+ junk ^= SkFastFourByteInterp256(src, dst, scale);
+ } else if (kScale) {
+ junk ^= SkFourByteInterp(src, dst, scale);
+ } else {
+ junk ^= SkFourByteInterp256(src, dst, scale);
+ }
+ }
+ }
+ }
+
+private:
+ SkString fName;
+ unsigned fScales[257]; // We need space for [0, 256].
+};
+
+#define COMMA ,
+DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA true>); )
+DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA false>); )
+DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA true>); )
+DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA false>); )
+#undef COMMA
diff --git a/gyp/bench.gyp b/gyp/bench.gyp
index 6c7c29d..2a852b7 100644
--- a/gyp/bench.gyp
+++ b/gyp/bench.gyp
@@ -33,6 +33,7 @@
'../bench/ChromeBench.cpp',
'../bench/CmapBench.cpp',
'../bench/ColorFilterBench.cpp',
+ '../bench/ColorPrivBench.cpp',
'../bench/CoverageBench.cpp',
'../bench/DashBench.cpp',
'../bench/DecodeBench.cpp',