| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 do { \ | 49 do { \ |
| 50 if (pred) { \ | 50 if (pred) { \ |
| 51 ++gScalarBench_NonStaticGlobal; \ | 51 ++gScalarBench_NonStaticGlobal; \ |
| 52 } \ | 52 } \ |
| 53 } while (0) | 53 } while (0) |
| 54 | 54 |
| 55 // having unknown values in our arrays can throw off the timing a lot, perhaps | 55 // having unknown values in our arrays can throw off the timing a lot, perhaps |
| 56 // handling NaN values is a lot slower. Anyway, this guy is just meant to put | 56 // handling NaN values is a lot slower. Anyway, this guy is just meant to put |
| 57 // reasonable values in our arrays. | 57 // reasonable values in our arrays. |
| 58 template <typename T> void init9(T array[9]) { | 58 template <typename T> void init9(T array[9]) { |
| 59 SkMWCRandom rand; | 59 SkRandom rand; |
| 60 for (int i = 0; i < 9; i++) { | 60 for (int i = 0; i < 9; i++) { |
| 61 array[i] = rand.nextSScalar1(); | 61 array[i] = rand.nextSScalar1(); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 class FloatComparisonBench : public ScalarBench { | 65 class FloatComparisonBench : public ScalarBench { |
| 66 public: | 66 public: |
| 67 FloatComparisonBench(void* param) : INHERITED(param, "compare_float") { | 67 FloatComparisonBench(void* param) : INHERITED(param, "compare_float") { |
| 68 init9(fArray); | 68 init9(fArray); |
| 69 } | 69 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 95 } | 95 } |
| 96 private: | 96 private: |
| 97 static const int32_t kPersp1Int = 0x3f800000; | 97 static const int32_t kPersp1Int = 0x3f800000; |
| 98 SkScalar fArray[9]; | 98 SkScalar fArray[9]; |
| 99 typedef ScalarBench INHERITED; | 99 typedef ScalarBench INHERITED; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 class IsFiniteScalarBench : public ScalarBench { | 102 class IsFiniteScalarBench : public ScalarBench { |
| 103 public: | 103 public: |
| 104 IsFiniteScalarBench(void* param) : INHERITED(param, "isfinite") { | 104 IsFiniteScalarBench(void* param) : INHERITED(param, "isfinite") { |
| 105 SkMWCRandom rand; | 105 SkRandom rand; |
| 106 for (size_t i = 0; i < ARRAY_N; ++i) { | 106 for (size_t i = 0; i < ARRAY_N; ++i) { |
| 107 fArray[i] = rand.nextSScalar1(); | 107 fArray[i] = rand.nextSScalar1(); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 protected: | 110 protected: |
| 111 virtual int mulLoopCount() const { return 1; } | 111 virtual int mulLoopCount() const { return 1; } |
| 112 virtual void performTest() SK_OVERRIDE { | 112 virtual void performTest() SK_OVERRIDE { |
| 113 int sum = 0; | 113 int sum = 0; |
| 114 for (size_t i = 0; i < ARRAY_N; ++i) { | 114 for (size_t i = 0; i < ARRAY_N; ++i) { |
| 115 // We pass -fArray[i], so the compiler can't cheat and treat the | 115 // We pass -fArray[i], so the compiler can't cheat and treat the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 134 | 134 |
| 135 class RectBoundsBench : public SkBenchmark { | 135 class RectBoundsBench : public SkBenchmark { |
| 136 enum { | 136 enum { |
| 137 PTS = 100, | 137 PTS = 100, |
| 138 N = SkBENCHLOOP(10000) | 138 N = SkBENCHLOOP(10000) |
| 139 }; | 139 }; |
| 140 SkPoint fPts[PTS]; | 140 SkPoint fPts[PTS]; |
| 141 | 141 |
| 142 public: | 142 public: |
| 143 RectBoundsBench(void* param) : INHERITED(param) { | 143 RectBoundsBench(void* param) : INHERITED(param) { |
| 144 SkMWCRandom rand; | 144 SkRandom rand; |
| 145 for (int i = 0; i < PTS; ++i) { | 145 for (int i = 0; i < PTS; ++i) { |
| 146 fPts[i].fX = rand.nextSScalar1(); | 146 fPts[i].fX = rand.nextSScalar1(); |
| 147 fPts[i].fY = rand.nextSScalar1(); | 147 fPts[i].fY = rand.nextSScalar1(); |
| 148 } | 148 } |
| 149 fIsRendering = false; | 149 fIsRendering = false; |
| 150 } | 150 } |
| 151 | 151 |
| 152 protected: | 152 protected: |
| 153 virtual const char* onGetName() SK_OVERRIDE { | 153 virtual const char* onGetName() SK_OVERRIDE { |
| 154 return "rect_bounds"; | 154 return "rect_bounds"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 169 | 169 |
| 170 static SkBenchmark* S0(void* p) { return new FloatComparisonBench(p); } | 170 static SkBenchmark* S0(void* p) { return new FloatComparisonBench(p); } |
| 171 static SkBenchmark* S1(void* p) { return new ForcedIntComparisonBench(p); } | 171 static SkBenchmark* S1(void* p) { return new ForcedIntComparisonBench(p); } |
| 172 static SkBenchmark* S2(void* p) { return new RectBoundsBench(p); } | 172 static SkBenchmark* S2(void* p) { return new RectBoundsBench(p); } |
| 173 static SkBenchmark* S3(void* p) { return new IsFiniteScalarBench(p); } | 173 static SkBenchmark* S3(void* p) { return new IsFiniteScalarBench(p); } |
| 174 | 174 |
| 175 static BenchRegistry gReg0(S0); | 175 static BenchRegistry gReg0(S0); |
| 176 static BenchRegistry gReg1(S1); | 176 static BenchRegistry gReg1(S1); |
| 177 static BenchRegistry gReg2(S2); | 177 static BenchRegistry gReg2(S2); |
| 178 static BenchRegistry gReg3(S3); | 178 static BenchRegistry gReg3(S3); |
| OLD | NEW |