| OLD | NEW |
| 1 #include "Benchmark.h" | 1 #include "Benchmark.h" |
| 2 #include "SkColorPriv.h" | 2 #include "SkColorPriv.h" |
| 3 #include "SkRandom.h" | 3 #include "SkRandom.h" |
| 4 #include "SkString.h" | 4 #include "SkString.h" |
| 5 | 5 |
| 6 template <bool kFast, bool kScale> | 6 template <bool kFast, bool kScale> |
| 7 class FourByteInterpBench : public Benchmark { | 7 class FourByteInterpBench : public Benchmark { |
| 8 public: | 8 public: |
| 9 FourByteInterpBench() { | 9 FourByteInterpBench() { |
| 10 fName.set("four_byte_interp"); | 10 fName.set("four_byte_interp"); |
| 11 fName.append(kFast ? "_fast" : "_slow"); | 11 fName.append(kFast ? "_fast" : "_slow"); |
| 12 fName.append(kScale ? "_255" : "_256"); | 12 fName.append(kScale ? "_255" : "_256"); |
| 13 } | 13 } |
| 14 | 14 |
| 15 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 15 bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 16 return backend == kNonRendering_Backend; | 16 return backend == kNonRendering_Backend; |
| 17 } | 17 } |
| 18 | 18 |
| 19 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } | 19 const char* onGetName() SK_OVERRIDE { return fName.c_str(); } |
| 20 | 20 |
| 21 virtual void onPreDraw() SK_OVERRIDE { | 21 void onPreDraw() SK_OVERRIDE { |
| 22 // A handful of random srcs and dsts. | 22 // A handful of random srcs and dsts. |
| 23 SkRandom rand; | 23 SkRandom rand; |
| 24 for (int i = 0; i < kInputs; i++) { | 24 for (int i = 0; i < kInputs; i++) { |
| 25 fSrcs[i] = SkPreMultiplyColor(rand.nextU()); | 25 fSrcs[i] = SkPreMultiplyColor(rand.nextU()); |
| 26 fDsts[i] = SkPreMultiplyColor(rand.nextU()); | 26 fDsts[i] = SkPreMultiplyColor(rand.nextU()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // We'll exhaustively test all scales instead of using random numbers. | 29 // We'll exhaustively test all scales instead of using random numbers. |
| 30 for (int i = 0; i <= 256; i++) { | 30 for (int i = 0; i <= 256; i++) { |
| 31 fScales[i] = i; | 31 fScales[i] = i; |
| 32 } | 32 } |
| 33 if (kScale) fScales[256] = 255; // We'll just do 255 twice if we're lim
ited to [0,255]. | 33 if (kScale) fScales[256] = 255; // We'll just do 255 twice if we're lim
ited to [0,255]. |
| 34 } | 34 } |
| 35 | 35 |
| 36 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { | 36 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { |
| 37 // We xor results of FourByteInterp into junk to make sure the function
runs. | 37 // We xor results of FourByteInterp into junk to make sure the function
runs. |
| 38 volatile SkPMColor junk = 0; | 38 volatile SkPMColor junk = 0; |
| 39 | 39 |
| 40 for (int loop = 0; loop < loops; loop++) { | 40 for (int loop = 0; loop < loops; loop++) { |
| 41 for (int i = 0; i < kInputs; i++) { | 41 for (int i = 0; i < kInputs; i++) { |
| 42 for (size_t j = 0; j <= 256; j++) { | 42 for (size_t j = 0; j <= 256; j++) { |
| 43 // Note: we really want to load src and dst here and not out
side in the i-loop. | 43 // Note: we really want to load src and dst here and not out
side in the i-loop. |
| 44 // If we put the loads there, a clever compiler will do the
not-insignificant | 44 // If we put the loads there, a clever compiler will do the
not-insignificant |
| 45 // work in the FourByteInterps that depends only on src and
dst outside this | 45 // work in the FourByteInterps that depends only on src and
dst outside this |
| 46 // loop, so we'd only be benchmarking the back half of those
functions that also | 46 // loop, so we'd only be benchmarking the back half of those
functions that also |
| (...skipping 25 matching lines...) Expand all Loading... |
| 72 volatile unsigned fDsts[kInputs]; | 72 volatile unsigned fDsts[kInputs]; |
| 73 unsigned fScales[257]; // We need space for [0, 256]. | 73 unsigned fScales[257]; // We need space for [0, 256]. |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 #define COMMA , | 76 #define COMMA , |
| 77 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA true>); ) | 77 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA true>); ) |
| 78 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA false>); ) | 78 DEF_BENCH( return SkNEW(FourByteInterpBench<true COMMA false>); ) |
| 79 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA true>); ) | 79 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA true>); ) |
| 80 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA false>); ) | 80 DEF_BENCH( return SkNEW(FourByteInterpBench<false COMMA false>); ) |
| 81 #undef COMMA | 81 #undef COMMA |
| OLD | NEW |