| OLD | NEW |
| 1 #include "Benchmark.h" | 1 #include "Benchmark.h" |
| 2 #include "SkPMFloat.h" | 2 #include "SkPMFloat.h" |
| 3 | 3 |
| 4 // Used to prevent the compiler from optimizing away the whole loop. | 4 // Used to prevent the compiler from optimizing away the whole loop. |
| 5 volatile uint32_t blackhole = 0; | 5 volatile uint32_t blackhole = 0; |
| 6 | 6 |
| 7 // Not a great random number generator, but it's very fast. | 7 // Not a great random number generator, but it's very fast. |
| 8 // The code we're measuring is quite fast, so low overhead is essential. | 8 // The code we're measuring is quite fast, so low overhead is essential. |
| 9 static uint32_t lcg_rand(uint32_t* seed) { | 9 static uint32_t lcg_rand(uint32_t* seed) { |
| 10 *seed *= 1664525; | 10 *seed *= 1664525; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 uint32_t junk = 0; | 23 uint32_t junk = 0; |
| 24 uint32_t seed = 0; | 24 uint32_t seed = 0; |
| 25 for (int i = 0; i < loops; i++) { | 25 for (int i = 0; i < loops; i++) { |
| 26 #ifdef SK_DEBUG | 26 #ifdef SK_DEBUG |
| 27 // Our SkASSERTs will remind us that it's technically required that
we premultiply. | 27 // Our SkASSERTs will remind us that it's technically required that
we premultiply. |
| 28 SkPMColor c = SkPreMultiplyColor(lcg_rand(&seed)); | 28 SkPMColor c = SkPreMultiplyColor(lcg_rand(&seed)); |
| 29 #else | 29 #else |
| 30 // But it's a lot faster not to, and this code won't really mind the
non-PM colors. | 30 // But it's a lot faster not to, and this code won't really mind the
non-PM colors. |
| 31 SkPMColor c = lcg_rand(&seed); | 31 SkPMColor c = lcg_rand(&seed); |
| 32 #endif | 32 #endif |
| 33 SkPMFloat pmf; | 33 SkPMFloat pmf = SkPMFloat::FromPMColor(c); |
| 34 pmf.set(c); | |
| 35 SkPMColor back = fClamp ? pmf.clamped() : pmf.get(); | 34 SkPMColor back = fClamp ? pmf.clamped() : pmf.get(); |
| 36 junk ^= back; | 35 junk ^= back; |
| 37 } | 36 } |
| 38 blackhole ^= junk; | 37 blackhole ^= junk; |
| 39 } | 38 } |
| 40 | 39 |
| 41 bool fClamp; | 40 bool fClamp; |
| 42 }; | 41 }; |
| 43 DEF_BENCH(return new PMFloatBench( true);) | 42 DEF_BENCH(return new PMFloatBench( true);) |
| 44 DEF_BENCH(return new PMFloatBench(false);) | 43 DEF_BENCH(return new PMFloatBench(false);) |
| OLD | NEW |