aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/PathIterBench.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-07 13:46:32 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-07 13:46:32 +0000
commitc56a83ca9c1011fadd25475188fc2ea08930ec41 (patch)
treef6b5d928836d29994b16d6359ec1681746e8dbb4 /bench/PathIterBench.cpp
parent99a6ef48e396901b6cfb007b49d592ffac2bc597 (diff)
add bench for SkPath::Iter and SkPath::RawIter
git-svn-id: http://skia.googlecode.com/svn/trunk@3844 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/PathIterBench.cpp')
-rw-r--r--bench/PathIterBench.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/bench/PathIterBench.cpp b/bench/PathIterBench.cpp
new file mode 100644
index 0000000000..8e4308ef13
--- /dev/null
+++ b/bench/PathIterBench.cpp
@@ -0,0 +1,96 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkBenchmark.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkColorPriv.h"
+#include "SkPaint.h"
+#include "SkRandom.h"
+#include "SkShader.h"
+#include "SkString.h"
+
+static int rand_pts(SkRandom& rand, SkPoint pts[4]) {
+ int n = rand.nextU() & 3;
+ n += 1;
+
+ for (int i = 0; i < n; ++i) {
+ pts[i].fX = rand.nextSScalar1();
+ pts[i].fY = rand.nextSScalar1();
+ }
+ return n;
+}
+
+class PathIterBench : public SkBenchmark {
+ SkString fName;
+ SkPath fPath;
+ bool fRaw;
+
+ enum { N = SkBENCHLOOP(500) };
+
+public:
+ PathIterBench(void* param, bool raw) : INHERITED(param) {
+ fName.printf("pathiter_%s", raw ? "raw" : "consume");
+ fRaw = raw;
+
+ SkRandom rand;
+ for (int i = 0; i < 1000; ++i) {
+ SkPoint pts[4];
+ int n = rand_pts(rand, pts);
+ switch (n) {
+ case 1:
+ fPath.moveTo(pts[0]);
+ break;
+ case 2:
+ fPath.lineTo(pts[1]);
+ break;
+ case 3:
+ fPath.quadTo(pts[1], pts[2]);
+ break;
+ case 4:
+ fPath.cubicTo(pts[1], pts[2], pts[3]);
+ break;
+ }
+ }
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return fName.c_str();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ if (fRaw) {
+ for (int i = 0; i < N; ++i) {
+ SkPath::RawIter iter(fPath);
+ SkPath::Verb verb;
+ SkPoint pts[4];
+
+ while ((verb = iter.next(pts)) != SkPath::kDone_Verb);
+ }
+ } else {
+ for (int i = 0; i < N; ++i) {
+ SkPath::Iter iter(fPath, false);
+ SkPath::Verb verb;
+ SkPoint pts[4];
+
+ while ((verb = iter.next(pts)) != SkPath::kDone_Verb);
+ }
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static SkBenchmark* F0(void* p) { return new PathIterBench(p, false); }
+static SkBenchmark* F1(void* p) { return new PathIterBench(p, true); }
+
+static BenchRegistry gR0(F0);
+static BenchRegistry gR1(F1);