| 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 "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkMatrixUtils.h" | 10 #include "SkMatrixUtils.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 virtual void onDraw(const int loops, SkCanvas*) { | 34 virtual void onDraw(const int loops, SkCanvas*) { |
| 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 gMatrixBench_NonStaticGlobal; | |
| 48 | |
| 49 #define always_do(pred) \ | |
| 50 do { \ | |
| 51 if (pred) { \ | |
| 52 ++gMatrixBench_NonStaticGlobal; \ | |
| 53 } \ | |
| 54 } while (0) | |
| 55 | 44 |
| 56 class EqualsMatrixBench : public MatrixBench { | 45 class EqualsMatrixBench : public MatrixBench { |
| 57 public: | 46 public: |
| 58 EqualsMatrixBench() : INHERITED("equals") {} | 47 EqualsMatrixBench() : INHERITED("equals") {} |
| 59 protected: | 48 protected: |
| 60 virtual void performTest() { | 49 virtual void performTest() { |
| 61 SkMatrix m0, m1, m2; | 50 SkMatrix m0, m1, m2; |
| 62 | 51 |
| 63 m0.reset(); | 52 m0.reset(); |
| 64 m1.reset(); | 53 m1.reset(); |
| 65 m2.reset(); | 54 m2.reset(); |
| 66 always_do(m0 == m1); | 55 |
| 67 always_do(m1 == m2); | 56 // xor into a volatile prevents these comparisons from being optimized a
way. |
| 68 always_do(m2 == m0); | 57 volatile bool junk = false; |
| 58 junk ^= (m0 == m1); |
| 59 junk ^= (m1 == m2); |
| 60 junk ^= (m2 == m0); |
| 69 } | 61 } |
| 70 private: | 62 private: |
| 71 typedef MatrixBench INHERITED; | 63 typedef MatrixBench INHERITED; |
| 72 }; | 64 }; |
| 73 | 65 |
| 74 class ScaleMatrixBench : public MatrixBench { | 66 class ScaleMatrixBench : public MatrixBench { |
| 75 public: | 67 public: |
| 76 ScaleMatrixBench() : INHERITED("scale") { | 68 ScaleMatrixBench() : INHERITED("scale") { |
| 77 fSX = fSY = 1.5f; | 69 fSX = fSY = 1.5f; |
| 78 fM0.reset(); | 70 fM0.reset(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 fArray[8] = (float) fRnd.nextS(); | 228 fArray[8] = (float) fRnd.nextS(); |
| 237 } | 229 } |
| 238 protected: | 230 protected: |
| 239 // Putting random generation of the matrix inside performTest() | 231 // Putting random generation of the matrix inside performTest() |
| 240 // would help us avoid anomalous runs, but takes up 25% or | 232 // would help us avoid anomalous runs, but takes up 25% or |
| 241 // more of the function time. | 233 // more of the function time. |
| 242 virtual void performTest() { | 234 virtual void performTest() { |
| 243 fMatrix.setAll(fArray[0], fArray[1], fArray[2], | 235 fMatrix.setAll(fArray[0], fArray[1], fArray[2], |
| 244 fArray[3], fArray[4], fArray[5], | 236 fArray[3], fArray[4], fArray[5], |
| 245 fArray[6], fArray[7], fArray[8]); | 237 fArray[6], fArray[7], fArray[8]); |
| 246 always_do(fMatrix.getType()); | 238 // xoring into a volatile prevents the compiler from optimizing these aw
ay |
| 239 volatile int junk = 0; |
| 240 junk ^= (fMatrix.getType()); |
| 247 fMatrix.dirtyMatrixTypeCache(); | 241 fMatrix.dirtyMatrixTypeCache(); |
| 248 always_do(fMatrix.getType()); | 242 junk ^= (fMatrix.getType()); |
| 249 fMatrix.dirtyMatrixTypeCache(); | 243 fMatrix.dirtyMatrixTypeCache(); |
| 250 always_do(fMatrix.getType()); | 244 junk ^= (fMatrix.getType()); |
| 251 fMatrix.dirtyMatrixTypeCache(); | 245 fMatrix.dirtyMatrixTypeCache(); |
| 252 always_do(fMatrix.getType()); | 246 junk ^= (fMatrix.getType()); |
| 253 fMatrix.dirtyMatrixTypeCache(); | 247 fMatrix.dirtyMatrixTypeCache(); |
| 254 always_do(fMatrix.getType()); | 248 junk ^= (fMatrix.getType()); |
| 255 fMatrix.dirtyMatrixTypeCache(); | 249 fMatrix.dirtyMatrixTypeCache(); |
| 256 always_do(fMatrix.getType()); | 250 junk ^= (fMatrix.getType()); |
| 257 fMatrix.dirtyMatrixTypeCache(); | 251 fMatrix.dirtyMatrixTypeCache(); |
| 258 always_do(fMatrix.getType()); | 252 junk ^= (fMatrix.getType()); |
| 259 fMatrix.dirtyMatrixTypeCache(); | 253 fMatrix.dirtyMatrixTypeCache(); |
| 260 always_do(fMatrix.getType()); | 254 junk ^= (fMatrix.getType()); |
| 261 } | 255 } |
| 262 private: | 256 private: |
| 263 SkMatrix fMatrix; | 257 SkMatrix fMatrix; |
| 264 float fArray[9]; | 258 float fArray[9]; |
| 265 SkRandom fRnd; | 259 SkRandom fRnd; |
| 266 typedef MatrixBench INHERITED; | 260 typedef MatrixBench INHERITED; |
| 267 }; | 261 }; |
| 268 | 262 |
| 269 class ScaleTransMixedMatrixBench : public MatrixBench { | 263 class ScaleTransMixedMatrixBench : public MatrixBench { |
| 270 public: | 264 public: |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 463 |
| 470 DEF_BENCH( return new InvertMapRectMatrixBench( | 464 DEF_BENCH( return new InvertMapRectMatrixBench( |
| 471 "invert_maprect_typemask_nonpersp", | 465 "invert_maprect_typemask_nonpersp", |
| 472 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | | 466 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
| 473 InvertMapRectMatrixBench::kScale_Flag | | 467 InvertMapRectMatrixBench::kScale_Flag | |
| 474 InvertMapRectMatrixBench::kRotate_Flag | | 468 InvertMapRectMatrixBench::kRotate_Flag | |
| 475 InvertMapRectMatrixBench::kTranslate_Flag); ) | 469 InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 476 | 470 |
| 477 DEF_BENCH( return new ScaleTransMixedMatrixBench(); ) | 471 DEF_BENCH( return new ScaleTransMixedMatrixBench(); ) |
| 478 DEF_BENCH( return new ScaleTransDoubleMatrixBench(); ) | 472 DEF_BENCH( return new ScaleTransDoubleMatrixBench(); ) |
| OLD | NEW |