OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
10 #include "SkMatrixUtils.h" | 10 #include "SkMatrixUtils.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 | 13 |
14 class MatrixBench : public SkBenchmark { | 14 class MatrixBench : public SkBenchmark { |
15 SkString fName; | 15 SkString fName; |
16 enum { N = 100000 }; | |
17 public: | 16 public: |
18 MatrixBench(void* param, const char name[]) : INHERITED(param) { | 17 MatrixBench(void* param, const char name[]) : INHERITED(param) { |
19 fName.printf("matrix_%s", name); | 18 fName.printf("matrix_%s", name); |
20 fIsRendering = false; | 19 fIsRendering = false; |
21 } | 20 } |
22 | 21 |
23 virtual void performTest() = 0; | 22 virtual void performTest() = 0; |
24 | 23 |
25 protected: | 24 protected: |
26 virtual int mulLoopCount() const { return 1; } | 25 virtual int mulLoopCount() const { return 1; } |
27 | 26 |
28 virtual const char* onGetName() { | 27 virtual const char* onGetName() { |
29 return fName.c_str(); | 28 return fName.c_str(); |
30 } | 29 } |
31 | 30 |
32 virtual void onDraw(SkCanvas*) { | 31 virtual void onDraw(SkCanvas*) { |
33 int n = SkBENCHLOOP(N * this->mulLoopCount()); | 32 for (int i = 0; i < this->getLoops(); i++) { |
34 for (int i = 0; i < n; i++) { | |
35 this->performTest(); | 33 this->performTest(); |
36 } | 34 } |
37 } | 35 } |
38 | 36 |
39 private: | 37 private: |
40 typedef SkBenchmark INHERITED; | 38 typedef SkBenchmark INHERITED; |
41 }; | 39 }; |
42 | 40 |
43 // we want to stop the compiler from eliminating code that it thinks is a no-op | 41 // we want to stop the compiler from eliminating code that it thinks is a no-op |
44 // so we have a non-static global we increment, hoping that will convince the | 42 // so we have a non-static global we increment, hoping that will convince the |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 float ty = fMatrix[SkMatrix::kMTransY]; | 288 float ty = fMatrix[SkMatrix::kMTransY]; |
291 do { | 289 do { |
292 dst->fY = SkScalarMulAdd(src->fY, my, ty); | 290 dst->fY = SkScalarMulAdd(src->fY, my, ty); |
293 dst->fX = SkScalarMulAdd(src->fX, mx, tx); | 291 dst->fX = SkScalarMulAdd(src->fX, mx, tx); |
294 src += 1; | 292 src += 1; |
295 dst += 1; | 293 dst += 1; |
296 } while (--count); | 294 } while (--count); |
297 } | 295 } |
298 private: | 296 private: |
299 enum { | 297 enum { |
300 kCount = SkBENCHLOOP(16) | 298 kCount = 16 |
301 }; | 299 }; |
302 SkMatrix fMatrix; | 300 SkMatrix fMatrix; |
303 SkPoint fSrc [16]; | 301 SkPoint fSrc [kCount]; |
304 SkPoint fDst [16]; | 302 SkPoint fDst [kCount]; |
305 SkRandom fRandom; | 303 SkRandom fRandom; |
306 typedef MatrixBench INHERITED; | 304 typedef MatrixBench INHERITED; |
307 }; | 305 }; |
308 | 306 |
309 class ScaleTransDoubleMatrixBench : public MatrixBench { | 307 class ScaleTransDoubleMatrixBench : public MatrixBench { |
310 public: | 308 public: |
311 ScaleTransDoubleMatrixBench(void* p) : INHERITED(p, "scaletrans_double") { | 309 ScaleTransDoubleMatrixBench(void* p) : INHERITED(p, "scaletrans_double") { |
312 init9(fMatrix); | 310 init9(fMatrix); |
313 int i; | 311 int i; |
314 for (i = 0; i < kCount; i++) { | 312 for (i = 0; i < kCount; i++) { |
(...skipping 15 matching lines...) Expand all Loading... | |
330 float ty = (float) fMatrix[SkMatrix::kMTransY]; | 328 float ty = (float) fMatrix[SkMatrix::kMTransY]; |
331 do { | 329 do { |
332 dst->fY = src->fY * my + ty; | 330 dst->fY = src->fY * my + ty; |
333 dst->fX = src->fX * mx + tx; | 331 dst->fX = src->fX * mx + tx; |
334 src += 1; | 332 src += 1; |
335 dst += 1; | 333 dst += 1; |
336 } while (--count); | 334 } while (--count); |
337 } | 335 } |
338 private: | 336 private: |
339 enum { | 337 enum { |
340 kCount = SkBENCHLOOP(16) | 338 kCount = 16 |
341 }; | 339 }; |
342 double fMatrix [9]; | 340 double fMatrix [9]; |
343 SkPoint fSrc [16]; | 341 SkPoint fSrc [kCount]; |
344 SkPoint fDst [16]; | 342 SkPoint fDst [kCount]; |
345 SkRandom fRandom; | 343 SkRandom fRandom; |
346 typedef MatrixBench INHERITED; | 344 typedef MatrixBench INHERITED; |
347 }; | 345 }; |
348 | 346 |
349 class DecomposeMatrixBench : public MatrixBench { | 347 class DecomposeMatrixBench : public MatrixBench { |
epoger
2013/09/04 19:18:26
Why this new DecomposeMatrixBench in patchset 9?
mtklein
2013/09/04 19:25:15
New at head after patchset 8.
| |
350 public: | 348 public: |
351 DecomposeMatrixBench(void* param) : INHERITED(param, "decompose") {} | 349 DecomposeMatrixBench(void* param) : INHERITED(param, "decompose") {} |
352 | 350 |
353 protected: | 351 protected: |
354 virtual void onPreDraw() { | 352 virtual void onPreDraw() { |
355 for (int i = 0; i < 10; ++i) { | 353 for (int i = 0; i < 10; ++i) { |
356 SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180) : 0.0f; | 354 SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180) : 0.0f; |
357 SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); | 355 SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); |
358 SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 300 0.f) : sx; | 356 SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 300 0.f) : sx; |
359 SkScalar rot1 = fRandom.nextRangeF(-180, 180); | 357 SkScalar rot1 = fRandom.nextRangeF(-180, 180); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 466 |
469 DEF_BENCH( return new InvertMapRectMatrixBench(p, | 467 DEF_BENCH( return new InvertMapRectMatrixBench(p, |
470 "invert_maprect_typemask_nonpersp", | 468 "invert_maprect_typemask_nonpersp", |
471 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | | 469 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
472 InvertMapRectMatrixBench::kScale_Flag | | 470 InvertMapRectMatrixBench::kScale_Flag | |
473 InvertMapRectMatrixBench::kRotate_Flag | | 471 InvertMapRectMatrixBench::kRotate_Flag | |
474 InvertMapRectMatrixBench::kTranslate_Flag); ) | 472 InvertMapRectMatrixBench::kTranslate_Flag); ) |
475 | 473 |
476 DEF_BENCH( return new ScaleTransMixedMatrixBench(p); ) | 474 DEF_BENCH( return new ScaleTransMixedMatrixBench(p); ) |
477 DEF_BENCH( return new ScaleTransDoubleMatrixBench(p); ) | 475 DEF_BENCH( return new ScaleTransDoubleMatrixBench(p); ) |
OLD | NEW |