OLD | NEW |
1 #include "SkBenchmark.h" | 1 #include "Benchmark.h" |
2 #include "SkColorPriv.h" | 2 #include "SkColorPriv.h" |
3 #include "SkMatrix.h" | 3 #include "SkMatrix.h" |
| 4 #include "SkPaint.h" |
4 #include "SkRandom.h" | 5 #include "SkRandom.h" |
5 #include "SkString.h" | 6 #include "SkString.h" |
6 #include "SkPaint.h" | |
7 | 7 |
8 static float sk_fsel(float pred, float result_ge, float result_lt) { | 8 static float sk_fsel(float pred, float result_ge, float result_lt) { |
9 return pred >= 0 ? result_ge : result_lt; | 9 return pred >= 0 ? result_ge : result_lt; |
10 } | 10 } |
11 | 11 |
12 static float fast_floor(float x) { | 12 static float fast_floor(float x) { |
13 // float big = sk_fsel(x, 0x1.0p+23, -0x1.0p+23); | 13 // float big = sk_fsel(x, 0x1.0p+23, -0x1.0p+23); |
14 float big = sk_fsel(x, (float)(1 << 23), -(float)(1 << 23)); | 14 float big = sk_fsel(x, (float)(1 << 23), -(float)(1 << 23)); |
15 return (x + big) - big; | 15 return (x + big) - big; |
16 } | 16 } |
17 | 17 |
18 class MathBench : public SkBenchmark { | 18 class MathBench : public Benchmark { |
19 enum { | 19 enum { |
20 kBuffer = 100, | 20 kBuffer = 100, |
21 }; | 21 }; |
22 SkString fName; | 22 SkString fName; |
23 float fSrc[kBuffer], fDst[kBuffer]; | 23 float fSrc[kBuffer], fDst[kBuffer]; |
24 public: | 24 public: |
25 MathBench(const char name[]) { | 25 MathBench(const char name[]) { |
26 fName.printf("math_%s", name); | 26 fName.printf("math_%s", name); |
27 | 27 |
28 SkRandom rand; | 28 SkRandom rand; |
(...skipping 18 matching lines...) Expand all Loading... |
47 } | 47 } |
48 | 48 |
49 virtual void onDraw(const int loops, SkCanvas*) { | 49 virtual void onDraw(const int loops, SkCanvas*) { |
50 int n = loops * this->mulLoopCount(); | 50 int n = loops * this->mulLoopCount(); |
51 for (int i = 0; i < n; i++) { | 51 for (int i = 0; i < n; i++) { |
52 this->performTest(fDst, fSrc, kBuffer); | 52 this->performTest(fDst, fSrc, kBuffer); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 typedef SkBenchmark INHERITED; | 57 typedef Benchmark INHERITED; |
58 }; | 58 }; |
59 | 59 |
60 class MathBenchU32 : public MathBench { | 60 class MathBenchU32 : public MathBench { |
61 public: | 61 public: |
62 MathBenchU32(const char name[]) : INHERITED(name) {} | 62 MathBenchU32(const char name[]) : INHERITED(name) {} |
63 | 63 |
64 protected: | 64 protected: |
65 virtual void performITest(uint32_t* SK_RESTRICT dst, | 65 virtual void performITest(uint32_t* SK_RESTRICT dst, |
66 const uint32_t* SK_RESTRICT src, | 66 const uint32_t* SK_RESTRICT src, |
67 int count) = 0; | 67 int count) = 0; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 static bool isFinite(const SkRect& r) { | 255 static bool isFinite(const SkRect& r) { |
256 // x * 0 will be NaN iff x is infinity or NaN. | 256 // x * 0 will be NaN iff x is infinity or NaN. |
257 // a + b will be NaN iff either a or b is NaN. | 257 // a + b will be NaN iff either a or b is NaN. |
258 float value = r.fLeft * 0 + r.fTop * 0 + r.fRight * 0 + r.fBottom * 0; | 258 float value = r.fLeft * 0 + r.fTop * 0 + r.fRight * 0 + r.fBottom * 0; |
259 | 259 |
260 // value is either NaN or it is finite (zero). | 260 // value is either NaN or it is finite (zero). |
261 // value==value will be true iff value is not NaN | 261 // value==value will be true iff value is not NaN |
262 return value == value; | 262 return value == value; |
263 } | 263 } |
264 | 264 |
265 class IsFiniteBench : public SkBenchmark { | 265 class IsFiniteBench : public Benchmark { |
266 enum { | 266 enum { |
267 N = 1000, | 267 N = 1000, |
268 }; | 268 }; |
269 float fData[N]; | 269 float fData[N]; |
270 public: | 270 public: |
271 | 271 |
272 IsFiniteBench(int index) { | 272 IsFiniteBench(int index) { |
273 SkRandom rand; | 273 SkRandom rand; |
274 | 274 |
275 for (int i = 0; i < N; ++i) { | 275 for (int i = 0; i < N; ++i) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 321 } |
322 | 322 |
323 virtual const char* onGetName() { | 323 virtual const char* onGetName() { |
324 return fName; | 324 return fName; |
325 } | 325 } |
326 | 326 |
327 private: | 327 private: |
328 IsFiniteProc fProc; | 328 IsFiniteProc fProc; |
329 const char* fName; | 329 const char* fName; |
330 | 330 |
331 typedef SkBenchmark INHERITED; | 331 typedef Benchmark INHERITED; |
332 }; | 332 }; |
333 | 333 |
334 class FloorBench : public SkBenchmark { | 334 class FloorBench : public Benchmark { |
335 enum { | 335 enum { |
336 ARRAY = 1000, | 336 ARRAY = 1000, |
337 }; | 337 }; |
338 float fData[ARRAY]; | 338 float fData[ARRAY]; |
339 bool fFast; | 339 bool fFast; |
340 public: | 340 public: |
341 | 341 |
342 FloorBench(bool fast) : fFast(fast) { | 342 FloorBench(bool fast) : fFast(fast) { |
343 SkRandom rand; | 343 SkRandom rand; |
344 | 344 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 virtual const char* onGetName() { | 385 virtual const char* onGetName() { |
386 return fName; | 386 return fName; |
387 } | 387 } |
388 | 388 |
389 private: | 389 private: |
390 const char* fName; | 390 const char* fName; |
391 | 391 |
392 typedef SkBenchmark INHERITED; | 392 typedef Benchmark INHERITED; |
393 }; | 393 }; |
394 | 394 |
395 class CLZBench : public SkBenchmark { | 395 class CLZBench : public Benchmark { |
396 enum { | 396 enum { |
397 ARRAY = 1000, | 397 ARRAY = 1000, |
398 }; | 398 }; |
399 uint32_t fData[ARRAY]; | 399 uint32_t fData[ARRAY]; |
400 bool fUsePortable; | 400 bool fUsePortable; |
401 | 401 |
402 public: | 402 public: |
403 CLZBench(bool usePortable) : fUsePortable(usePortable) { | 403 CLZBench(bool usePortable) : fUsePortable(usePortable) { |
404 | 404 |
405 SkRandom rand; | 405 SkRandom rand; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 virtual const char* onGetName() { | 445 virtual const char* onGetName() { |
446 return fName; | 446 return fName; |
447 } | 447 } |
448 | 448 |
449 private: | 449 private: |
450 const char* fName; | 450 const char* fName; |
451 | 451 |
452 typedef SkBenchmark INHERITED; | 452 typedef Benchmark INHERITED; |
453 }; | 453 }; |
454 | 454 |
455 /////////////////////////////////////////////////////////////////////////////// | 455 /////////////////////////////////////////////////////////////////////////////// |
456 | 456 |
457 class NormalizeBench : public SkBenchmark { | 457 class NormalizeBench : public Benchmark { |
458 enum { | 458 enum { |
459 ARRAY =1000, | 459 ARRAY =1000, |
460 }; | 460 }; |
461 SkVector fVec[ARRAY]; | 461 SkVector fVec[ARRAY]; |
462 | 462 |
463 public: | 463 public: |
464 NormalizeBench() { | 464 NormalizeBench() { |
465 SkRandom rand; | 465 SkRandom rand; |
466 for (int i = 0; i < ARRAY; ++i) { | 466 for (int i = 0; i < ARRAY; ++i) { |
467 fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1()); | 467 fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1()); |
(...skipping 21 matching lines...) Expand all Loading... |
489 } | 489 } |
490 } | 490 } |
491 | 491 |
492 virtual const char* onGetName() { | 492 virtual const char* onGetName() { |
493 return fName; | 493 return fName; |
494 } | 494 } |
495 | 495 |
496 private: | 496 private: |
497 const char* fName; | 497 const char* fName; |
498 | 498 |
499 typedef SkBenchmark INHERITED; | 499 typedef Benchmark INHERITED; |
500 }; | 500 }; |
501 | 501 |
502 /////////////////////////////////////////////////////////////////////////////// | 502 /////////////////////////////////////////////////////////////////////////////// |
503 | 503 |
504 class FixedMathBench : public SkBenchmark { | 504 class FixedMathBench : public Benchmark { |
505 enum { | 505 enum { |
506 N = 1000, | 506 N = 1000, |
507 }; | 507 }; |
508 float fData[N]; | 508 float fData[N]; |
509 SkFixed fResult[N]; | 509 SkFixed fResult[N]; |
510 public: | 510 public: |
511 | 511 |
512 FixedMathBench() { | 512 FixedMathBench() { |
513 SkRandom rand; | 513 SkRandom rand; |
514 for (int i = 0; i < N; ++i) { | 514 for (int i = 0; i < N; ++i) { |
(...skipping 18 matching lines...) Expand all Loading... |
533 if (paint.getAlpha() == 0) { | 533 if (paint.getAlpha() == 0) { |
534 SkDebugf("%d\n", fResult[0]); | 534 SkDebugf("%d\n", fResult[0]); |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 virtual const char* onGetName() { | 538 virtual const char* onGetName() { |
539 return "float_to_fixed"; | 539 return "float_to_fixed"; |
540 } | 540 } |
541 | 541 |
542 private: | 542 private: |
543 typedef SkBenchmark INHERITED; | 543 typedef Benchmark INHERITED; |
544 }; | 544 }; |
545 | 545 |
546 /////////////////////////////////////////////////////////////////////////////// | 546 /////////////////////////////////////////////////////////////////////////////// |
547 | 547 |
548 template <typename T> | 548 template <typename T> |
549 class DivModBench : public SkBenchmark { | 549 class DivModBench : public Benchmark { |
550 SkString fName; | 550 SkString fName; |
551 public: | 551 public: |
552 explicit DivModBench(const char* name) { | 552 explicit DivModBench(const char* name) { |
553 fName.printf("divmod_%s", name); | 553 fName.printf("divmod_%s", name); |
554 } | 554 } |
555 | 555 |
556 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 556 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
557 return backend == kNonRendering_Backend; | 557 return backend == kNonRendering_Backend; |
558 } | 558 } |
559 | 559 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 602 |
603 DEF_BENCH( return new FloorBench(false); ) | 603 DEF_BENCH( return new FloorBench(false); ) |
604 DEF_BENCH( return new FloorBench(true); ) | 604 DEF_BENCH( return new FloorBench(true); ) |
605 | 605 |
606 DEF_BENCH( return new CLZBench(false); ) | 606 DEF_BENCH( return new CLZBench(false); ) |
607 DEF_BENCH( return new CLZBench(true); ) | 607 DEF_BENCH( return new CLZBench(true); ) |
608 | 608 |
609 DEF_BENCH( return new NormalizeBench(); ) | 609 DEF_BENCH( return new NormalizeBench(); ) |
610 | 610 |
611 DEF_BENCH( return new FixedMathBench(); ) | 611 DEF_BENCH( return new FixedMathBench(); ) |
OLD | NEW |