OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkMatrix44.h" | 9 #include "SkMatrix44.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 | 12 |
13 class Matrix44Bench : public Benchmark { | 13 class Matrix44Bench : public Benchmark { |
14 SkString fName; | 14 SkString fName; |
15 public: | 15 public: |
16 Matrix44Bench(const char name[]) { | 16 Matrix44Bench(const char name[]) { |
17 fName.printf("matrix44_%s", name); | 17 fName.printf("matrix44_%s", name); |
18 } | 18 } |
19 | 19 |
20 bool isSuitableFor(Backend backend) override { | 20 bool isSuitableFor(Backend backend) override { |
21 return backend == kNonRendering_Backend; | 21 return backend == kNonRendering_Backend; |
22 } | 22 } |
23 | 23 |
24 virtual void performTest() = 0; | 24 virtual void performTest() = 0; |
25 | 25 |
26 protected: | 26 protected: |
27 virtual int mulLoopCount() const { return 1; } | 27 virtual int mulLoopCount() const { return 1; } |
28 | 28 |
29 virtual const char* onGetName() { | 29 const char* onGetName() override { |
30 return fName.c_str(); | 30 return fName.c_str(); |
31 } | 31 } |
32 | 32 |
33 virtual void onDraw(const int loops, SkCanvas*) { | 33 void onDraw(const int loops, SkCanvas*) override { |
34 for (int i = 0; i < loops; i++) { | 34 for (int i = 0; i < loops; i++) { |
35 this->performTest(); | 35 this->performTest(); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 private: | 39 private: |
40 typedef Benchmark INHERITED; | 40 typedef Benchmark INHERITED; |
41 }; | 41 }; |
42 | 42 |
43 class EqualsMatrix44Bench : public Matrix44Bench { | 43 class EqualsMatrix44Bench : public Matrix44Bench { |
44 public: | 44 public: |
45 EqualsMatrix44Bench() | 45 EqualsMatrix44Bench() |
46 : INHERITED("equals") | 46 : INHERITED("equals") |
47 , fM0(SkMatrix44::kIdentity_Constructor) | 47 , fM0(SkMatrix44::kIdentity_Constructor) |
48 , fM1(SkMatrix44::kIdentity_Constructor) | 48 , fM1(SkMatrix44::kIdentity_Constructor) |
49 , fM2(SkMatrix44::kIdentity_Constructor) | 49 , fM2(SkMatrix44::kIdentity_Constructor) |
50 { | 50 { |
51 fM1.set(0, 0, 0); | 51 fM1.set(0, 0, 0); |
52 fM2.set(3, 3, 0); | 52 fM2.set(3, 3, 0); |
53 } | 53 } |
54 protected: | 54 protected: |
55 virtual void performTest() { | 55 void performTest() override { |
56 for (int i = 0; i < 10; ++i) { | 56 for (int i = 0; i < 10; ++i) { |
57 (void) (fM0 == fM1); | 57 (void) (fM0 == fM1); |
58 (void) (fM1 == fM2); | 58 (void) (fM1 == fM2); |
59 (void) (fM2 == fM0); | 59 (void) (fM2 == fM0); |
60 } | 60 } |
61 } | 61 } |
62 private: | 62 private: |
63 SkMatrix44 fM0, fM1, fM2; | 63 SkMatrix44 fM0, fM1, fM2; |
64 typedef Matrix44Bench INHERITED; | 64 typedef Matrix44Bench INHERITED; |
65 }; | 65 }; |
66 | 66 |
67 class SetIdentityMatrix44Bench : public Matrix44Bench { | 67 class SetIdentityMatrix44Bench : public Matrix44Bench { |
68 public: | 68 public: |
69 SetIdentityMatrix44Bench() | 69 SetIdentityMatrix44Bench() |
70 : INHERITED("setidentity") | 70 : INHERITED("setidentity") |
71 , mat(SkMatrix44::kIdentity_Constructor) | 71 , mat(SkMatrix44::kIdentity_Constructor) |
72 { | 72 { |
73 double rowMajor[16] = | 73 double rowMajor[16] = |
74 { 1, 2, 3, 4, | 74 { 1, 2, 3, 4, |
75 5, 6, 7, 8, | 75 5, 6, 7, 8, |
76 9, 10, 11, 12, | 76 9, 10, 11, 12, |
77 13, 14, 15, 16}; | 77 13, 14, 15, 16}; |
78 mat.setRowMajord(rowMajor); | 78 mat.setRowMajord(rowMajor); |
79 } | 79 } |
80 protected: | 80 protected: |
81 virtual void performTest() { | 81 void performTest() override { |
82 for (int i = 0; i < 10; ++i) { | 82 for (int i = 0; i < 10; ++i) { |
83 mat.setIdentity(); | 83 mat.setIdentity(); |
84 } | 84 } |
85 } | 85 } |
86 private: | 86 private: |
87 SkMatrix44 mat; | 87 SkMatrix44 mat; |
88 typedef Matrix44Bench INHERITED; | 88 typedef Matrix44Bench INHERITED; |
89 }; | 89 }; |
90 | 90 |
91 class PreScaleMatrix44Bench : public Matrix44Bench { | 91 class PreScaleMatrix44Bench : public Matrix44Bench { |
92 public: | 92 public: |
93 PreScaleMatrix44Bench() | 93 PreScaleMatrix44Bench() |
94 : INHERITED("prescale") | 94 : INHERITED("prescale") |
95 , fM0(SkMatrix44::kUninitialized_Constructor) | 95 , fM0(SkMatrix44::kUninitialized_Constructor) |
96 { | 96 { |
97 fX = fY = fZ = SkDoubleToMScalar(1.5); | 97 fX = fY = fZ = SkDoubleToMScalar(1.5); |
98 } | 98 } |
99 protected: | 99 protected: |
100 virtual void performTest() { | 100 void performTest() override { |
101 fM0.reset(); | 101 fM0.reset(); |
102 for (int i = 0; i < 10; ++i) { | 102 for (int i = 0; i < 10; ++i) { |
103 fM0.preScale(fX, fY, fZ); | 103 fM0.preScale(fX, fY, fZ); |
104 } | 104 } |
105 } | 105 } |
106 private: | 106 private: |
107 SkMatrix44 fM0; | 107 SkMatrix44 fM0; |
108 SkMScalar fX, fY, fZ; | 108 SkMScalar fX, fY, fZ; |
109 typedef Matrix44Bench INHERITED; | 109 typedef Matrix44Bench INHERITED; |
110 }; | 110 }; |
(...skipping 16 matching lines...) Expand all Loading... |
127 fM0.setDouble(2, 0, -9.1); | 127 fM0.setDouble(2, 0, -9.1); |
128 fM0.setDouble(2, 1, 10.1); | 128 fM0.setDouble(2, 1, 10.1); |
129 fM0.setDouble(2, 2, 11.1); | 129 fM0.setDouble(2, 2, 11.1); |
130 fM0.setDouble(2, 3, -12.1); | 130 fM0.setDouble(2, 3, -12.1); |
131 fM0.setDouble(3, 0, -13.1); | 131 fM0.setDouble(3, 0, -13.1); |
132 fM0.setDouble(3, 1, 14.1); | 132 fM0.setDouble(3, 1, 14.1); |
133 fM0.setDouble(3, 2, -15.1); | 133 fM0.setDouble(3, 2, -15.1); |
134 fM0.setDouble(3, 3, 16.1); | 134 fM0.setDouble(3, 3, 16.1); |
135 } | 135 } |
136 protected: | 136 protected: |
137 virtual void performTest() { | 137 void performTest() override { |
138 for (int i = 0; i < 10; ++i) { | 138 for (int i = 0; i < 10; ++i) { |
139 fM0.invert(&fM1); | 139 fM0.invert(&fM1); |
140 } | 140 } |
141 } | 141 } |
142 private: | 142 private: |
143 SkMatrix44 fM0, fM1; | 143 SkMatrix44 fM0, fM1; |
144 typedef Matrix44Bench INHERITED; | 144 typedef Matrix44Bench INHERITED; |
145 }; | 145 }; |
146 | 146 |
147 class InvertAffineMatrix44Bench : public Matrix44Bench { | 147 class InvertAffineMatrix44Bench : public Matrix44Bench { |
(...skipping 11 matching lines...) Expand all Loading... |
159 fM0.setDouble(1, 1, -6.1); | 159 fM0.setDouble(1, 1, -6.1); |
160 fM0.setDouble(1, 2, 7.1); | 160 fM0.setDouble(1, 2, 7.1); |
161 fM0.setDouble(1, 3, 8.1); | 161 fM0.setDouble(1, 3, 8.1); |
162 fM0.setDouble(2, 0, -9.1); | 162 fM0.setDouble(2, 0, -9.1); |
163 fM0.setDouble(2, 1, 10.1); | 163 fM0.setDouble(2, 1, 10.1); |
164 fM0.setDouble(2, 2, 11.1); | 164 fM0.setDouble(2, 2, 11.1); |
165 fM0.setDouble(2, 3, -12.1); | 165 fM0.setDouble(2, 3, -12.1); |
166 // bottom row (perspective component) remains (0, 0, 0, 1). | 166 // bottom row (perspective component) remains (0, 0, 0, 1). |
167 } | 167 } |
168 protected: | 168 protected: |
169 virtual void performTest() { | 169 void performTest() override { |
170 for (int i = 0; i < 10; ++i) { | 170 for (int i = 0; i < 10; ++i) { |
171 fM0.invert(&fM1); | 171 fM0.invert(&fM1); |
172 } | 172 } |
173 } | 173 } |
174 private: | 174 private: |
175 SkMatrix44 fM0, fM1; | 175 SkMatrix44 fM0, fM1; |
176 typedef Matrix44Bench INHERITED; | 176 typedef Matrix44Bench INHERITED; |
177 }; | 177 }; |
178 | 178 |
179 class InvertScaleTranslateMatrix44Bench : public Matrix44Bench { | 179 class InvertScaleTranslateMatrix44Bench : public Matrix44Bench { |
180 public: | 180 public: |
181 InvertScaleTranslateMatrix44Bench() | 181 InvertScaleTranslateMatrix44Bench() |
182 : INHERITED("invertscaletranslate") | 182 : INHERITED("invertscaletranslate") |
183 , fM0(SkMatrix44::kIdentity_Constructor) | 183 , fM0(SkMatrix44::kIdentity_Constructor) |
184 , fM1(SkMatrix44::kUninitialized_Constructor) | 184 , fM1(SkMatrix44::kUninitialized_Constructor) |
185 { | 185 { |
186 fM0.setDouble(0, 0, -1.1); | 186 fM0.setDouble(0, 0, -1.1); |
187 fM0.setDouble(0, 3, 4.1); | 187 fM0.setDouble(0, 3, 4.1); |
188 | 188 |
189 fM0.setDouble(1, 1, -6.1); | 189 fM0.setDouble(1, 1, -6.1); |
190 fM0.setDouble(1, 3, 8.1); | 190 fM0.setDouble(1, 3, 8.1); |
191 | 191 |
192 fM0.setDouble(2, 2, 11.1); | 192 fM0.setDouble(2, 2, 11.1); |
193 fM0.setDouble(2, 3, -12.1); | 193 fM0.setDouble(2, 3, -12.1); |
194 } | 194 } |
195 protected: | 195 protected: |
196 virtual void performTest() { | 196 void performTest() override { |
197 for (int i = 0; i < 10; ++i) { | 197 for (int i = 0; i < 10; ++i) { |
198 fM0.invert(&fM1); | 198 fM0.invert(&fM1); |
199 } | 199 } |
200 } | 200 } |
201 private: | 201 private: |
202 SkMatrix44 fM0, fM1; | 202 SkMatrix44 fM0, fM1; |
203 typedef Matrix44Bench INHERITED; | 203 typedef Matrix44Bench INHERITED; |
204 }; | 204 }; |
205 | 205 |
206 class InvertTranslateMatrix44Bench : public Matrix44Bench { | 206 class InvertTranslateMatrix44Bench : public Matrix44Bench { |
207 public: | 207 public: |
208 InvertTranslateMatrix44Bench() | 208 InvertTranslateMatrix44Bench() |
209 : INHERITED("inverttranslate") | 209 : INHERITED("inverttranslate") |
210 , fM0(SkMatrix44::kIdentity_Constructor) | 210 , fM0(SkMatrix44::kIdentity_Constructor) |
211 , fM1(SkMatrix44::kUninitialized_Constructor) | 211 , fM1(SkMatrix44::kUninitialized_Constructor) |
212 { | 212 { |
213 fM0.setDouble(0, 3, 4.1); | 213 fM0.setDouble(0, 3, 4.1); |
214 fM0.setDouble(1, 3, 8.1); | 214 fM0.setDouble(1, 3, 8.1); |
215 fM0.setDouble(2, 3, -12.1); | 215 fM0.setDouble(2, 3, -12.1); |
216 } | 216 } |
217 protected: | 217 protected: |
218 virtual void performTest() { | 218 void performTest() override { |
219 for (int i = 0; i < 10; ++i) { | 219 for (int i = 0; i < 10; ++i) { |
220 fM0.invert(&fM1); | 220 fM0.invert(&fM1); |
221 } | 221 } |
222 } | 222 } |
223 private: | 223 private: |
224 SkMatrix44 fM0, fM1; | 224 SkMatrix44 fM0, fM1; |
225 typedef Matrix44Bench INHERITED; | 225 typedef Matrix44Bench INHERITED; |
226 }; | 226 }; |
227 | 227 |
228 class PostScaleMatrix44Bench : public Matrix44Bench { | 228 class PostScaleMatrix44Bench : public Matrix44Bench { |
229 public: | 229 public: |
230 PostScaleMatrix44Bench() | 230 PostScaleMatrix44Bench() |
231 : INHERITED("postscale") | 231 : INHERITED("postscale") |
232 , fM0(SkMatrix44::kUninitialized_Constructor) | 232 , fM0(SkMatrix44::kUninitialized_Constructor) |
233 { | 233 { |
234 fX = fY = fZ = SkDoubleToMScalar(1.5); | 234 fX = fY = fZ = SkDoubleToMScalar(1.5); |
235 } | 235 } |
236 protected: | 236 protected: |
237 virtual void performTest() { | 237 void performTest() override { |
238 fM0.reset(); | 238 fM0.reset(); |
239 for (int i = 0; i < 10; ++i) { | 239 for (int i = 0; i < 10; ++i) { |
240 fM0.postScale(fX, fY, fZ); | 240 fM0.postScale(fX, fY, fZ); |
241 } | 241 } |
242 } | 242 } |
243 private: | 243 private: |
244 SkMatrix44 fM0; | 244 SkMatrix44 fM0; |
245 SkMScalar fX, fY, fZ; | 245 SkMScalar fX, fY, fZ; |
246 typedef Matrix44Bench INHERITED; | 246 typedef Matrix44Bench INHERITED; |
247 }; | 247 }; |
(...skipping 14 matching lines...) Expand all Loading... |
262 } else { | 262 } else { |
263 SkRandom rand; | 263 SkRandom rand; |
264 for (int x = 0; x < 4; x++) { | 264 for (int x = 0; x < 4; x++) { |
265 for (int y = 0; y < 4; y++) { | 265 for (int y = 0; y < 4; y++) { |
266 fM1.setFloat(x,y, rand.nextF()); | 266 fM1.setFloat(x,y, rand.nextF()); |
267 fM2.setFloat(x,y, rand.nextF()); | 267 fM2.setFloat(x,y, rand.nextF()); |
268 }} | 268 }} |
269 } | 269 } |
270 } | 270 } |
271 protected: | 271 protected: |
272 virtual void performTest() { | 272 void performTest() override { |
273 fM0.reset(); // just to normalize this test with prescale/postscale | 273 fM0.reset(); // just to normalize this test with prescale/postscale |
274 for (int i = 0; i < 10000; ++i) { | 274 for (int i = 0; i < 10000; ++i) { |
275 fM0.setConcat(fM1, fM2); | 275 fM0.setConcat(fM1, fM2); |
276 } | 276 } |
277 } | 277 } |
278 private: | 278 private: |
279 SkMatrix44 fM0, fM1, fM2; | 279 SkMatrix44 fM0, fM1, fM2; |
280 typedef Matrix44Bench INHERITED; | 280 typedef Matrix44Bench INHERITED; |
281 }; | 281 }; |
282 | 282 |
283 class GetTypeMatrix44Bench : public Matrix44Bench { | 283 class GetTypeMatrix44Bench : public Matrix44Bench { |
284 public: | 284 public: |
285 GetTypeMatrix44Bench() | 285 GetTypeMatrix44Bench() |
286 : INHERITED("gettype") | 286 : INHERITED("gettype") |
287 , fMatrix(SkMatrix44::kIdentity_Constructor) | 287 , fMatrix(SkMatrix44::kIdentity_Constructor) |
288 {} | 288 {} |
289 protected: | 289 protected: |
290 // Putting random generation of the matrix inside performTest() | 290 // Putting random generation of the matrix inside performTest() |
291 // would help us avoid anomalous runs, but takes up 25% or | 291 // would help us avoid anomalous runs, but takes up 25% or |
292 // more of the function time. | 292 // more of the function time. |
293 virtual void performTest() { | 293 void performTest() override { |
294 for (int i = 0; i < 20; ++i) { | 294 for (int i = 0; i < 20; ++i) { |
295 fMatrix.set(1, 2, 1); // to invalidate the type-cache | 295 fMatrix.set(1, 2, 1); // to invalidate the type-cache |
296 fMatrix.getType(); | 296 fMatrix.getType(); |
297 } | 297 } |
298 } | 298 } |
299 private: | 299 private: |
300 SkMatrix44 fMatrix; | 300 SkMatrix44 fMatrix; |
301 typedef Matrix44Bench INHERITED; | 301 typedef Matrix44Bench INHERITED; |
302 }; | 302 }; |
303 | 303 |
304 DEF_BENCH( return new SetIdentityMatrix44Bench(); ) | 304 DEF_BENCH( return new SetIdentityMatrix44Bench(); ) |
305 DEF_BENCH( return new EqualsMatrix44Bench(); ) | 305 DEF_BENCH( return new EqualsMatrix44Bench(); ) |
306 DEF_BENCH( return new PreScaleMatrix44Bench(); ) | 306 DEF_BENCH( return new PreScaleMatrix44Bench(); ) |
307 DEF_BENCH( return new PostScaleMatrix44Bench(); ) | 307 DEF_BENCH( return new PostScaleMatrix44Bench(); ) |
308 DEF_BENCH( return new InvertMatrix44Bench(); ) | 308 DEF_BENCH( return new InvertMatrix44Bench(); ) |
309 DEF_BENCH( return new InvertAffineMatrix44Bench(); ) | 309 DEF_BENCH( return new InvertAffineMatrix44Bench(); ) |
310 DEF_BENCH( return new InvertScaleTranslateMatrix44Bench(); ) | 310 DEF_BENCH( return new InvertScaleTranslateMatrix44Bench(); ) |
311 DEF_BENCH( return new InvertTranslateMatrix44Bench(); ) | 311 DEF_BENCH( return new InvertTranslateMatrix44Bench(); ) |
312 DEF_BENCH( return new SetConcatMatrix44Bench(true); ) | 312 DEF_BENCH( return new SetConcatMatrix44Bench(true); ) |
313 DEF_BENCH( return new SetConcatMatrix44Bench(false); ) | 313 DEF_BENCH( return new SetConcatMatrix44Bench(false); ) |
314 DEF_BENCH( return new GetTypeMatrix44Bench(); ) | 314 DEF_BENCH( return new GetTypeMatrix44Bench(); ) |
OLD | NEW |