blob: 1b0ec21dc96126e2e95e1f2924c20dcd0ad26904 [file] [log] [blame]
hstern0446a3c2016-08-08 12:28:13 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// for std::max
9#include <algorithm>
10
11#include "Benchmark.h"
12#include "SkCurveMeasure.h"
13#include "SkPath.h"
14#include "SkPathMeasure.h"
15#include "SkString.h"
16
17#define NORMALIZE_LOOPS
18
19class MeasureBench : public Benchmark {
20 protected:
21 SkString fName;
22
23 SkPath fPath;
24
25 bool fUsePathMeasure;
26 float fSize;
27 size_t fPieces;
28
29 SkPoint fPts[3];
30
31 public:
32 MeasureBench(bool usePathMeasure, float size, size_t pieces)
33 : fUsePathMeasure(usePathMeasure),
34 fSize(size),
35 fPieces(pieces) {
36 fName.printf("measure_%s_%.1f_" SK_SIZE_T_SPECIFIER,
37 fUsePathMeasure ? "pathMeasure" : "curveMeasure", fSize,
38 fPieces);
39
40 auto p1 = SkPoint::Make(0, 0);
41 auto p2 = SkPoint::Make(30*fSize, 0);
42 auto p3 = SkPoint::Make(15*fSize, 15*fSize);
43
44 fPts[0] = p1;
45 fPts[1] = p2;
46 fPts[2] = p3;
47
48 this->setPath();
49 }
50
51 protected:
52 const char* onGetName() override { return fName.c_str(); }
53
54 void setPath() {
55 fPath.moveTo(fPts[0]);
56 fPath.quadTo(fPts[1], fPts[2]);
57 }
58
59 int numLoops() {
60#ifdef NORMALIZE_LOOPS
61 // arbitrary heuristic
62 return std::max(2, 10000 / ((int)fSize*(int)fPieces));
63#else
64 return 1000;
65#endif // NORMALIZE_LOOPS
66 }
67
68 //// measurement code
69
70 void do_pathMeasure(SkCanvas* canvas) {
71 SkPathMeasure meas(fPath, false);
72
73 SkScalar totalLength = meas.getLength();
74 SkScalar pieceLength = totalLength / fPieces;
75
76 SkPoint point;
77 for (size_t i = 0; i <= fPieces; i++) {
78 if (meas.getPosTan(i * pieceLength, &point, nullptr)) {
79 };
80 }
81 }
82
83 void do_curveMeasure(SkCanvas* canvas) {
84 SkCurveMeasure meas(fPts, kQuad_SegType);
85
86 SkScalar totalLength = meas.getLength();
87 SkScalar pieceLength = totalLength / fPieces;
88
89 SkPoint point;
90 for (size_t i = 0; i <= fPieces; i++) {
hstern80ac5912016-08-10 07:45:31 -070091 meas.getPosTanTime(i*pieceLength, &point, nullptr, nullptr);
hstern0446a3c2016-08-08 12:28:13 -070092 }
93 }
94
95 void onDraw(int loops, SkCanvas* canvas) override {
96 int inner_loops = numLoops();
97 for (int i = 0; i < loops; i++) {
98 for (int j = 0; j < inner_loops; j++) {
99 if (fUsePathMeasure) {
100 do_pathMeasure(canvas);
101 }
102 else {
103 do_curveMeasure(canvas);
104 }
105 }
106 }
107 }
108
109 private:
110 typedef Benchmark INHERITED;
111};
112
113///////////////////////////////////////////////////////////////////////////////
114
115DEF_BENCH(return new MeasureBench(true, 1, 2);)
116DEF_BENCH(return new MeasureBench(true, 2, 2);)
117DEF_BENCH(return new MeasureBench(true, 10, 2);)
118DEF_BENCH(return new MeasureBench(true, 100, 2);)
119DEF_BENCH(return new MeasureBench(true, 1000, 2);)
120
121DEF_BENCH(return new MeasureBench(true, 1, 1);)
122DEF_BENCH(return new MeasureBench(true, 1, 2);)
123DEF_BENCH(return new MeasureBench(true, 1, 3);)
124DEF_BENCH(return new MeasureBench(true, 1, 4);)
125DEF_BENCH(return new MeasureBench(true, 1, 5);)
126DEF_BENCH(return new MeasureBench(true, 2, 1);)
127DEF_BENCH(return new MeasureBench(true, 2, 2);)
128DEF_BENCH(return new MeasureBench(true, 2, 3);)
129DEF_BENCH(return new MeasureBench(true, 2, 4);)
130DEF_BENCH(return new MeasureBench(true, 2, 5);)
131DEF_BENCH(return new MeasureBench(true, 10, 10);)
132DEF_BENCH(return new MeasureBench(true, 10, 20);)
133DEF_BENCH(return new MeasureBench(true, 10, 30);)
134DEF_BENCH(return new MeasureBench(true, 10, 40);)
135DEF_BENCH(return new MeasureBench(true, 10, 50);)
136DEF_BENCH(return new MeasureBench(true, 100, 100);)
137DEF_BENCH(return new MeasureBench(true, 100, 200);)
138DEF_BENCH(return new MeasureBench(true, 100, 300);)
139DEF_BENCH(return new MeasureBench(true, 100, 400);)
140DEF_BENCH(return new MeasureBench(true, 100, 500);)
141DEF_BENCH(return new MeasureBench(true, 1000, 1000);)
142DEF_BENCH(return new MeasureBench(true, 1000, 2000);)
143DEF_BENCH(return new MeasureBench(true, 1000, 3000);)
144DEF_BENCH(return new MeasureBench(true, 1000, 4000);)
145DEF_BENCH(return new MeasureBench(true, 1000, 5000);)
146
147DEF_BENCH(return new MeasureBench(false, 1, 2);)
148DEF_BENCH(return new MeasureBench(false, 2, 2);)
149DEF_BENCH(return new MeasureBench(false, 10, 2);)
150DEF_BENCH(return new MeasureBench(false, 100, 2);)
151DEF_BENCH(return new MeasureBench(false, 1000, 2);)
152
153DEF_BENCH(return new MeasureBench(false, 1, 1);)
154DEF_BENCH(return new MeasureBench(false, 1, 2);)
155DEF_BENCH(return new MeasureBench(false, 1, 3);)
156DEF_BENCH(return new MeasureBench(false, 1, 4);)
157DEF_BENCH(return new MeasureBench(false, 1, 5);)
158DEF_BENCH(return new MeasureBench(false, 2, 1);)
159DEF_BENCH(return new MeasureBench(false, 2, 2);)
160DEF_BENCH(return new MeasureBench(false, 2, 3);)
161DEF_BENCH(return new MeasureBench(false, 2, 4);)
162DEF_BENCH(return new MeasureBench(false, 2, 5);)
163DEF_BENCH(return new MeasureBench(false, 10, 10);)
164DEF_BENCH(return new MeasureBench(false, 10, 20);)
165DEF_BENCH(return new MeasureBench(false, 10, 30);)
166DEF_BENCH(return new MeasureBench(false, 10, 40);)
167DEF_BENCH(return new MeasureBench(false, 10, 50);)
168DEF_BENCH(return new MeasureBench(false, 100, 100);)
169DEF_BENCH(return new MeasureBench(false, 100, 200);)
170DEF_BENCH(return new MeasureBench(false, 100, 300);)
171DEF_BENCH(return new MeasureBench(false, 100, 400);)
172DEF_BENCH(return new MeasureBench(false, 100, 500);)
173DEF_BENCH(return new MeasureBench(false, 1000, 1000);)
174DEF_BENCH(return new MeasureBench(false, 1000, 2000);)
175DEF_BENCH(return new MeasureBench(false, 1000, 3000);)
176DEF_BENCH(return new MeasureBench(false, 1000, 4000);)
177DEF_BENCH(return new MeasureBench(false, 1000, 5000);)