aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/MatrixBench.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-01 15:11:22 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-01 15:11:22 +0000
commit3fb5187647397e056843c1f41a508992be22175d (patch)
tree119a14084dd42d5334140525d599548b32bb4612 /bench/MatrixBench.cpp
parentac2e663762cb88dfea334d77052c6428b1a07d87 (diff)
speed-up SkMatrix::preScale by 3x, by special-casing it instead of just calling
concat. Inspired by the profile of the fishtank site git-svn-id: http://skia.googlecode.com/svn/trunk@1462 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/MatrixBench.cpp')
-rw-r--r--bench/MatrixBench.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/bench/MatrixBench.cpp b/bench/MatrixBench.cpp
new file mode 100644
index 0000000000..1c99ab433e
--- /dev/null
+++ b/bench/MatrixBench.cpp
@@ -0,0 +1,90 @@
+#include "SkBenchmark.h"
+#include "SkMatrix.h"
+#include "SkString.h"
+
+class MatrixBench : public SkBenchmark {
+ SkString fName;
+ enum { N = 100000 };
+public:
+ MatrixBench(void* param, const char name[]) : INHERITED(param) {
+ fName.printf("matrix_%s", name);
+ }
+
+ virtual void performTest() = 0;
+
+protected:
+ virtual const char* onGetName() {
+ return fName.c_str();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ for (int i = 0; i < N; i++) {
+ this->performTest();
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+// we want to stop the compiler from eliminating code that it thinks is a no-op
+// so we have a non-static global we increment, hoping that will convince the
+// compiler to execute everything
+int gMatrixBench_NonStaticGlobal;
+
+#define always_do(pred) \
+ do { \
+ if (pred) { \
+ ++gMatrixBench_NonStaticGlobal; \
+ } \
+ } while (0)
+
+class EqualsMatrixBench : public MatrixBench {
+public:
+ EqualsMatrixBench(void* param) : INHERITED(param, "equals") {}
+protected:
+ virtual void performTest() {
+ SkMatrix m0, m1, m2;
+
+ m0.reset();
+ m1.reset();
+ m2.reset();
+ always_do(m0 == m1);
+ always_do(m1 == m2);
+ always_do(m2 == m0);
+ always_do(m0.getType());
+ always_do(m1.getType());
+ always_do(m2.getType());
+ }
+private:
+ typedef MatrixBench INHERITED;
+};
+
+class ScaleMatrixBench : public MatrixBench {
+public:
+ ScaleMatrixBench(void* param) : INHERITED(param, "scale") {
+
+ fM0.reset();
+ fM1.setScale(fSX, fSY);
+ fM2.setTranslate(fSX, fSY);
+ fSX = fSY = SkFloatToScalar(1.5f);
+ }
+protected:
+ virtual void performTest() {
+ SkMatrix m;
+ m = fM0; m.preScale(fSX, fSY);
+ m = fM1; m.preScale(fSX, fSY);
+ m = fM2; m.preScale(fSX, fSY);
+ }
+private:
+ SkMatrix fM0, fM1, fM2;
+ SkScalar fSX, fSY;
+ typedef MatrixBench INHERITED;
+};
+
+static SkBenchmark* M0(void* p) { return new EqualsMatrixBench(p); }
+static SkBenchmark* M1(void* p) { return new ScaleMatrixBench(p); }
+
+static BenchRegistry gReg0(M0);
+static BenchRegistry gReg1(M1);
+