Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: bench/PathIterBench.cpp

Issue 1126993003: experimental path-builder Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/PathIterBench.cpp
diff --git a/bench/PathIterBench.cpp b/bench/PathIterBench.cpp
index 2da2594c5e6cff80604084fc2a70b8e1eb7aee6b..c6375bbbcc9ef10922c4acbb6bd175928e3279d4 100644
--- a/bench/PathIterBench.cpp
+++ b/bench/PathIterBench.cpp
@@ -14,6 +14,7 @@
#include "SkRandom.h"
#include "SkShader.h"
#include "SkString.h"
+#include "SkPathIter.h"
static int rand_pts(SkRandom& rand, SkPoint pts[4]) {
int n = rand.nextU() & 3;
@@ -26,14 +27,20 @@ static int rand_pts(SkRandom& rand, SkPoint pts[4]) {
return n;
}
+enum IterType {
+ kRaw,
+ kConsume,
+ kNew
+};
+
class PathIterBench : public Benchmark {
SkString fName;
SkPath fPath;
- bool fRaw;
+ IterType fRaw;
public:
- PathIterBench(bool raw) {
- fName.printf("pathiter_%s", raw ? "raw" : "consume");
+ PathIterBench(IterType raw) {
+ fName.printf("pathiter_%s", raw == 0 ? "raw" : (raw == 1 ? "consume" : "new"));
fRaw = raw;
SkRandom rand;
@@ -61,28 +68,47 @@ public:
return backend == kNonRendering_Backend;
}
+ virtual void handlePts(const SkPoint pts[]) {}
+
protected:
const char* onGetName() override {
return fName.c_str();
}
void onDraw(const int loops, SkCanvas*) override {
- if (fRaw) {
- for (int i = 0; i < loops; ++i) {
- SkPath::RawIter iter(fPath);
- SkPath::Verb verb;
- SkPoint pts[4];
+ for (int j = 0; j < 1000; ++j) {
+ switch (fRaw) {
+ case kRaw:
+ for (int i = 0; i < loops; ++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 < loops; ++i) {
- SkPath::Iter iter(fPath, false);
- SkPath::Verb verb;
- SkPoint pts[4];
+ while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
+ this->handlePts(pts);
+ }
+ }
+ break;
+ case kConsume:
+ for (int i = 0; i < loops; ++i) {
+ SkPath::Iter iter(fPath, false);
+ SkPath::Verb verb;
+ SkPoint pts[4];
- while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { }
- }
+ while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
+ this->handlePts(pts);
+ }
+ }
+ break;
+ case kNew: {
+ for (int i = 0; i < loops; ++i) {
+ SkPathIter iter(fPath);
+ while (iter.next()) {
+ this->handlePts(iter.currPts());
+ }
+ }
+ } break;
+ }
}
}
@@ -90,7 +116,6 @@ private:
typedef Benchmark INHERITED;
};
-///////////////////////////////////////////////////////////////////////////////
-
-DEF_BENCH( return new PathIterBench(false); )
-DEF_BENCH( return new PathIterBench(true); )
+DEF_BENCH( return new PathIterBench(kRaw); )
+DEF_BENCH( return new PathIterBench(kConsume); )
+DEF_BENCH( return new PathIterBench(kNew); )
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698