| OLD | NEW |
| 1 #include "SkBenchmark.h" | 1 #include "SkBenchmark.h" |
| 2 #include "SkColorPriv.h" | 2 #include "SkColorPriv.h" |
| 3 #include "SkMatrix.h" | 3 #include "SkMatrix.h" |
| 4 #include "SkRandom.h" | 4 #include "SkRandom.h" |
| 5 #include "SkString.h" | 5 #include "SkString.h" |
| 6 #include "SkPaint.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 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const float* SK_RESTRICT src, | 39 const float* SK_RESTRICT src, |
| 40 int count) = 0; | 40 int count) = 0; |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 virtual int mulLoopCount() const { return 1; } | 43 virtual int mulLoopCount() const { return 1; } |
| 44 | 44 |
| 45 virtual const char* onGetName() { | 45 virtual const char* onGetName() { |
| 46 return fName.c_str(); | 46 return fName.c_str(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual void onDraw(SkCanvas*) { | 49 virtual void onDraw(const int loops, SkCanvas*) { |
| 50 int n = this->getLoops() * 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 SkBenchmark INHERITED; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 class MathBenchU32 : public MathBench { | 60 class MathBenchU32 : public MathBench { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 fProc = gRec[index].fProc; | 283 fProc = gRec[index].fProc; |
| 284 fName = gRec[index].fName; | 284 fName = gRec[index].fName; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 288 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 289 return backend == kNonRendering_Backend; | 289 return backend == kNonRendering_Backend; |
| 290 } | 290 } |
| 291 | 291 |
| 292 protected: | 292 protected: |
| 293 virtual void onDraw(SkCanvas*) { | 293 virtual void onDraw(const int loops, SkCanvas*) { |
| 294 IsFiniteProc proc = fProc; | 294 IsFiniteProc proc = fProc; |
| 295 const float* data = fData; | 295 const float* data = fData; |
| 296 // do this so the compiler won't throw away the function call | 296 // do this so the compiler won't throw away the function call |
| 297 int counter = 0; | 297 int counter = 0; |
| 298 | 298 |
| 299 if (proc) { | 299 if (proc) { |
| 300 for (int j = 0; j < this->getLoops(); ++j) { | 300 for (int j = 0; j < loops; ++j) { |
| 301 for (int i = 0; i < N - 4; ++i) { | 301 for (int i = 0; i < N - 4; ++i) { |
| 302 counter += proc(&data[i]); | 302 counter += proc(&data[i]); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 } else { | 305 } else { |
| 306 for (int j = 0; j < this->getLoops(); ++j) { | 306 for (int j = 0; j < loops; ++j) { |
| 307 for (int i = 0; i < N - 4; ++i) { | 307 for (int i = 0; i < N - 4; ++i) { |
| 308 const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]); | 308 const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]); |
| 309 if (false) { // avoid bit rot, suppress warning | 309 if (false) { // avoid bit rot, suppress warning |
| 310 isFinite(*r); | 310 isFinite(*r); |
| 311 } | 311 } |
| 312 counter += r->isFinite(); | 312 counter += r->isFinite(); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 | 316 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 356 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 357 return backend == kNonRendering_Backend; | 357 return backend == kNonRendering_Backend; |
| 358 } | 358 } |
| 359 | 359 |
| 360 virtual void process(float) {} | 360 virtual void process(float) {} |
| 361 | 361 |
| 362 protected: | 362 protected: |
| 363 virtual void onDraw(SkCanvas*) { | 363 virtual void onDraw(const int loops, SkCanvas*) { |
| 364 SkRandom rand; | 364 SkRandom rand; |
| 365 float accum = 0; | 365 float accum = 0; |
| 366 const float* data = fData; | 366 const float* data = fData; |
| 367 | 367 |
| 368 if (fFast) { | 368 if (fFast) { |
| 369 for (int j = 0; j < this->getLoops(); ++j) { | 369 for (int j = 0; j < loops; ++j) { |
| 370 for (int i = 0; i < ARRAY; ++i) { | 370 for (int i = 0; i < ARRAY; ++i) { |
| 371 accum += fast_floor(data[i]); | 371 accum += fast_floor(data[i]); |
| 372 } | 372 } |
| 373 this->process(accum); | 373 this->process(accum); |
| 374 } | 374 } |
| 375 } else { | 375 } else { |
| 376 for (int j = 0; j < this->getLoops(); ++j) { | 376 for (int j = 0; j < loops; ++j) { |
| 377 for (int i = 0; i < ARRAY; ++i) { | 377 for (int i = 0; i < ARRAY; ++i) { |
| 378 accum += sk_float_floor(data[i]); | 378 accum += sk_float_floor(data[i]); |
| 379 } | 379 } |
| 380 this->process(accum); | 380 this->process(accum); |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 virtual const char* onGetName() { | 385 virtual const char* onGetName() { |
| 386 return fName; | 386 return fName; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 415 } | 415 } |
| 416 | 416 |
| 417 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 417 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 418 return backend == kNonRendering_Backend; | 418 return backend == kNonRendering_Backend; |
| 419 } | 419 } |
| 420 | 420 |
| 421 // just so the compiler doesn't remove our loops | 421 // just so the compiler doesn't remove our loops |
| 422 virtual void process(int) {} | 422 virtual void process(int) {} |
| 423 | 423 |
| 424 protected: | 424 protected: |
| 425 virtual void onDraw(SkCanvas*) { | 425 virtual void onDraw(const int loops, SkCanvas*) { |
| 426 int accum = 0; | 426 int accum = 0; |
| 427 | 427 |
| 428 if (fUsePortable) { | 428 if (fUsePortable) { |
| 429 for (int j = 0; j < this->getLoops(); ++j) { | 429 for (int j = 0; j < loops; ++j) { |
| 430 for (int i = 0; i < ARRAY; ++i) { | 430 for (int i = 0; i < ARRAY; ++i) { |
| 431 accum += SkCLZ_portable(fData[i]); | 431 accum += SkCLZ_portable(fData[i]); |
| 432 } | 432 } |
| 433 this->process(accum); | 433 this->process(accum); |
| 434 } | 434 } |
| 435 } else { | 435 } else { |
| 436 for (int j = 0; j < this->getLoops(); ++j) { | 436 for (int j = 0; j < loops; ++j) { |
| 437 for (int i = 0; i < ARRAY; ++i) { | 437 for (int i = 0; i < ARRAY; ++i) { |
| 438 accum += SkCLZ(fData[i]); | 438 accum += SkCLZ(fData[i]); |
| 439 } | 439 } |
| 440 this->process(accum); | 440 this->process(accum); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 virtual const char* onGetName() { | 445 virtual const char* onGetName() { |
| 446 return fName; | 446 return fName; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 471 } | 471 } |
| 472 | 472 |
| 473 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 473 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 474 return backend == kNonRendering_Backend; | 474 return backend == kNonRendering_Backend; |
| 475 } | 475 } |
| 476 | 476 |
| 477 // just so the compiler doesn't remove our loops | 477 // just so the compiler doesn't remove our loops |
| 478 virtual void process(int) {} | 478 virtual void process(int) {} |
| 479 | 479 |
| 480 protected: | 480 protected: |
| 481 virtual void onDraw(SkCanvas*) { | 481 virtual void onDraw(const int loops, SkCanvas*) { |
| 482 int accum = 0; | 482 int accum = 0; |
| 483 | 483 |
| 484 for (int j = 0; j < this->getLoops(); ++j) { | 484 for (int j = 0; j < loops; ++j) { |
| 485 for (int i = 0; i < ARRAY; ++i) { | 485 for (int i = 0; i < ARRAY; ++i) { |
| 486 accum += fVec[i].normalize(); | 486 accum += fVec[i].normalize(); |
| 487 } | 487 } |
| 488 this->process(accum); | 488 this->process(accum); |
| 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 SkBenchmark INHERITED; |
| 500 }; | 500 }; |
| 501 | 501 |
| 502 /////////////////////////////////////////////////////////////////////////////// | 502 /////////////////////////////////////////////////////////////////////////////// |
| 503 | 503 |
| 504 class FixedMathBench : public SkBenchmark { | 504 class FixedMathBench : public SkBenchmark { |
| 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 < this->getLoops(); ++i) { | 514 for (int i = 0; i < N; ++i) { |
| 515 fData[i%N] = rand.nextSScalar1(); | 515 fData[i] = rand.nextSScalar1(); |
| 516 } | 516 } |
| 517 | 517 |
| 518 } | 518 } |
| 519 | 519 |
| 520 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 520 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 521 return backend == kNonRendering_Backend; | 521 return backend == kNonRendering_Backend; |
| 522 } | 522 } |
| 523 | 523 |
| 524 protected: | 524 protected: |
| 525 virtual void onDraw(SkCanvas*) { | 525 virtual void onDraw(const int loops, SkCanvas*) { |
| 526 for (int j = 0; j < this->getLoops(); ++j) { | 526 for (int j = 0; j < loops; ++j) { |
| 527 for (int i = 0; i < N - 4; ++i) { | 527 for (int i = 0; i < N - 4; ++i) { |
| 528 fResult[i] = SkFloatToFixed(fData[i]); | 528 fResult[i] = SkFloatToFixed(fData[i]); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 SkPaint paint; | 532 SkPaint paint; |
| 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 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 |
| 560 protected: | 560 protected: |
| 561 virtual const char* onGetName() { | 561 virtual const char* onGetName() { |
| 562 return fName.c_str(); | 562 return fName.c_str(); |
| 563 } | 563 } |
| 564 | 564 |
| 565 virtual void onDraw(SkCanvas*) { | 565 virtual void onDraw(const int loops, SkCanvas*) { |
| 566 volatile T a = 0, b = 0; | 566 volatile T a = 0, b = 0; |
| 567 T div = 0, mod = 0; | 567 T div = 0, mod = 0; |
| 568 for (int i = 0; i < this->getLoops(); i++) { | 568 for (int i = 0; i < loops; i++) { |
| 569 if ((T)i == 0) continue; // Small T will wrap around. | 569 if ((T)i == 0) continue; // Small T will wrap around. |
| 570 SkTDivMod((T)(i+1), (T)i, &div, &mod); | 570 SkTDivMod((T)(i+1), (T)i, &div, &mod); |
| 571 a ^= div; | 571 a ^= div; |
| 572 b ^= mod; | 572 b ^= mod; |
| 573 } | 573 } |
| 574 } | 574 } |
| 575 }; | 575 }; |
| 576 DEF_BENCH(return new DivModBench<uint8_t>("uint8_t")) | 576 DEF_BENCH(return new DivModBench<uint8_t>("uint8_t")) |
| 577 DEF_BENCH(return new DivModBench<uint16_t>("uint16_t")) | 577 DEF_BENCH(return new DivModBench<uint16_t>("uint16_t")) |
| 578 DEF_BENCH(return new DivModBench<uint32_t>("uint32_t")) | 578 DEF_BENCH(return new DivModBench<uint32_t>("uint32_t")) |
| (...skipping 23 matching lines...) Expand all 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 |