| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
| 9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 virtual void onDraw(const int loops, SkCanvas* canvas) { | 34 virtual void onDraw(const int loops, SkCanvas* canvas) { |
| 35 for (int i = 0; i < loops; i++) { | 35 for (int i = 0; i < loops; i++) { |
| 36 this->performTest(); | 36 this->performTest(); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 typedef SkBenchmark INHERITED; | 41 typedef SkBenchmark INHERITED; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // we want to stop the compiler from eliminating code that it thinks is a no-op |
| 45 // so we have a non-static global we increment, hoping that will convince the |
| 46 // compiler to execute everything |
| 47 int gScalarBench_NonStaticGlobal; |
| 48 |
| 49 #define always_do(pred) \ |
| 50 do { \ |
| 51 if (pred) { \ |
| 52 ++gScalarBench_NonStaticGlobal; \ |
| 53 } \ |
| 54 } while (0) |
| 55 |
| 44 // having unknown values in our arrays can throw off the timing a lot, perhaps | 56 // having unknown values in our arrays can throw off the timing a lot, perhaps |
| 45 // handling NaN values is a lot slower. Anyway, this guy is just meant to put | 57 // handling NaN values is a lot slower. Anyway, this guy is just meant to put |
| 46 // reasonable values in our arrays. | 58 // reasonable values in our arrays. |
| 47 template <typename T> void init9(T array[9]) { | 59 template <typename T> void init9(T array[9]) { |
| 48 SkRandom rand; | 60 SkRandom rand; |
| 49 for (int i = 0; i < 9; i++) { | 61 for (int i = 0; i < 9; i++) { |
| 50 array[i] = rand.nextSScalar1(); | 62 array[i] = rand.nextSScalar1(); |
| 51 } | 63 } |
| 52 } | 64 } |
| 53 | 65 |
| 54 class FloatComparisonBench : public ScalarBench { | 66 class FloatComparisonBench : public ScalarBench { |
| 55 public: | 67 public: |
| 56 FloatComparisonBench() : INHERITED("compare_float") { | 68 FloatComparisonBench() : INHERITED("compare_float") { |
| 57 init9(fArray); | 69 init9(fArray); |
| 58 } | 70 } |
| 59 protected: | 71 protected: |
| 60 virtual int mulLoopCount() const { return 4; } | 72 virtual int mulLoopCount() const { return 4; } |
| 61 virtual void performTest() { | 73 virtual void performTest() { |
| 62 // xoring into a volatile prevents the compiler from optimizing these ch
ecks away. | 74 always_do(fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f); |
| 63 volatile bool junk = false; | 75 always_do(fArray[2] != 0.0f || fArray[5] != 0.0f); |
| 64 junk ^= (fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f); | |
| 65 junk ^= (fArray[2] != 0.0f || fArray[5] != 0.0f); | |
| 66 } | 76 } |
| 67 private: | 77 private: |
| 68 float fArray[9]; | 78 float fArray[9]; |
| 69 typedef ScalarBench INHERITED; | 79 typedef ScalarBench INHERITED; |
| 70 }; | 80 }; |
| 71 | 81 |
| 72 class ForcedIntComparisonBench : public ScalarBench { | 82 class ForcedIntComparisonBench : public ScalarBench { |
| 73 public: | 83 public: |
| 74 ForcedIntComparisonBench() | 84 ForcedIntComparisonBench() |
| 75 : INHERITED("compare_forced_int") { | 85 : INHERITED("compare_forced_int") { |
| 76 init9(fArray); | 86 init9(fArray); |
| 77 } | 87 } |
| 78 protected: | 88 protected: |
| 79 virtual int mulLoopCount() const { return 4; } | 89 virtual int mulLoopCount() const { return 4; } |
| 80 virtual void performTest() { | 90 virtual void performTest() { |
| 81 // xoring into a volatile prevents the compiler from optimizing these ch
ecks away. | 91 always_do(SkScalarAs2sCompliment(fArray[6]) | |
| 82 volatile bool junk = false; | 92 SkScalarAs2sCompliment(fArray[7]) | |
| 83 junk ^= (SkScalarAs2sCompliment(fArray[6]) | | 93 (SkScalarAs2sCompliment(fArray[8]) - kPersp1Int)); |
| 84 SkScalarAs2sCompliment(fArray[7]) | | 94 always_do(SkScalarAs2sCompliment(fArray[2]) | |
| 85 (SkScalarAs2sCompliment(fArray[8]) - kPersp1Int)); | 95 SkScalarAs2sCompliment(fArray[5])); |
| 86 junk ^= (SkScalarAs2sCompliment(fArray[2]) | | |
| 87 SkScalarAs2sCompliment(fArray[5])); | |
| 88 } | 96 } |
| 89 private: | 97 private: |
| 90 static const int32_t kPersp1Int = 0x3f800000; | 98 static const int32_t kPersp1Int = 0x3f800000; |
| 91 SkScalar fArray[9]; | 99 SkScalar fArray[9]; |
| 92 typedef ScalarBench INHERITED; | 100 typedef ScalarBench INHERITED; |
| 93 }; | 101 }; |
| 94 | 102 |
| 95 class IsFiniteScalarBench : public ScalarBench { | 103 class IsFiniteScalarBench : public ScalarBench { |
| 96 public: | 104 public: |
| 97 IsFiniteScalarBench() : INHERITED("isfinite") { | 105 IsFiniteScalarBench() : INHERITED("isfinite") { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 private: | 167 private: |
| 160 typedef SkBenchmark INHERITED; | 168 typedef SkBenchmark INHERITED; |
| 161 }; | 169 }; |
| 162 | 170 |
| 163 /////////////////////////////////////////////////////////////////////////////// | 171 /////////////////////////////////////////////////////////////////////////////// |
| 164 | 172 |
| 165 DEF_BENCH( return new FloatComparisonBench(); ) | 173 DEF_BENCH( return new FloatComparisonBench(); ) |
| 166 DEF_BENCH( return new ForcedIntComparisonBench(); ) | 174 DEF_BENCH( return new ForcedIntComparisonBench(); ) |
| 167 DEF_BENCH( return new RectBoundsBench(); ) | 175 DEF_BENCH( return new RectBoundsBench(); ) |
| 168 DEF_BENCH( return new IsFiniteScalarBench(); ) | 176 DEF_BENCH( return new IsFiniteScalarBench(); ) |
| OLD | NEW |