Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Side by Side Diff: bench/MathBench.cpp

Issue 23576015: Change old PRG to be SkLCGRandom; change new one to SkRandom (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix some spurious SkMWCRandoms Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bench/LineBench.cpp ('k') | bench/MatrixBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
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 SkBenchmark {
19 enum { 19 enum {
20 kBuffer = 100, 20 kBuffer = 100,
21 kLoop = 10000 21 kLoop = 10000
22 }; 22 };
23 SkString fName; 23 SkString fName;
24 float fSrc[kBuffer], fDst[kBuffer]; 24 float fSrc[kBuffer], fDst[kBuffer];
25 public: 25 public:
26 MathBench(void* param, const char name[]) : INHERITED(param) { 26 MathBench(void* param, const char name[]) : INHERITED(param) {
27 fName.printf("math_%s", name); 27 fName.printf("math_%s", name);
28 28
29 SkMWCRandom rand; 29 SkRandom rand;
30 for (int i = 0; i < kBuffer; ++i) { 30 for (int i = 0; i < kBuffer; ++i) {
31 fSrc[i] = rand.nextSScalar1(); 31 fSrc[i] = rand.nextSScalar1();
32 } 32 }
33 33
34 fIsRendering = false; 34 fIsRendering = false;
35 } 35 }
36 36
37 virtual void performTest(float* SK_RESTRICT dst, 37 virtual void performTest(float* SK_RESTRICT dst,
38 const float* SK_RESTRICT src, 38 const float* SK_RESTRICT src,
39 int count) = 0; 39 int count) = 0;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 class IsFiniteBench : public SkBenchmark { 248 class IsFiniteBench : public SkBenchmark {
249 enum { 249 enum {
250 N = SkBENCHLOOP(1000), 250 N = SkBENCHLOOP(1000),
251 NN = SkBENCHLOOP(1000), 251 NN = SkBENCHLOOP(1000),
252 }; 252 };
253 float fData[N]; 253 float fData[N];
254 public: 254 public:
255 255
256 IsFiniteBench(void* param, int index) : INHERITED(param) { 256 IsFiniteBench(void* param, int index) : INHERITED(param) {
257 SkMWCRandom rand; 257 SkRandom rand;
258 258
259 for (int i = 0; i < N; ++i) { 259 for (int i = 0; i < N; ++i) {
260 fData[i] = rand.nextSScalar1(); 260 fData[i] = rand.nextSScalar1();
261 } 261 }
262 262
263 if (index < 0) { 263 if (index < 0) {
264 fProc = NULL; 264 fProc = NULL;
265 fName = "isfinite_rect"; 265 fName = "isfinite_rect";
266 } else { 266 } else {
267 fProc = gRec[index].fProc; 267 fProc = gRec[index].fProc;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 class FloorBench : public SkBenchmark { 315 class FloorBench : public SkBenchmark {
316 enum { 316 enum {
317 ARRAY = SkBENCHLOOP(1000), 317 ARRAY = SkBENCHLOOP(1000),
318 LOOP = SkBENCHLOOP(1000), 318 LOOP = SkBENCHLOOP(1000),
319 }; 319 };
320 float fData[ARRAY]; 320 float fData[ARRAY];
321 bool fFast; 321 bool fFast;
322 public: 322 public:
323 323
324 FloorBench(void* param, bool fast) : INHERITED(param), fFast(fast) { 324 FloorBench(void* param, bool fast) : INHERITED(param), fFast(fast) {
325 SkMWCRandom rand; 325 SkRandom rand;
326 326
327 for (int i = 0; i < ARRAY; ++i) { 327 for (int i = 0; i < ARRAY; ++i) {
328 fData[i] = rand.nextSScalar1(); 328 fData[i] = rand.nextSScalar1();
329 } 329 }
330 330
331 if (fast) { 331 if (fast) {
332 fName = "floor_fast"; 332 fName = "floor_fast";
333 } else { 333 } else {
334 fName = "floor_std"; 334 fName = "floor_std";
335 } 335 }
336 fIsRendering = false; 336 fIsRendering = false;
337 } 337 }
338 338
339 virtual void process(float) {} 339 virtual void process(float) {}
340 340
341 protected: 341 protected:
342 virtual void onDraw(SkCanvas*) { 342 virtual void onDraw(SkCanvas*) {
343 SkMWCRandom rand; 343 SkRandom rand;
344 float accum = 0; 344 float accum = 0;
345 const float* data = fData; 345 const float* data = fData;
346 346
347 if (fFast) { 347 if (fFast) {
348 for (int j = 0; j < LOOP; ++j) { 348 for (int j = 0; j < LOOP; ++j) {
349 for (int i = 0; i < ARRAY; ++i) { 349 for (int i = 0; i < ARRAY; ++i) {
350 accum += fast_floor(data[i]); 350 accum += fast_floor(data[i]);
351 } 351 }
352 this->process(accum); 352 this->process(accum);
353 } 353 }
(...skipping 23 matching lines...) Expand all
377 LOOP = SkBENCHLOOP(5000), 377 LOOP = SkBENCHLOOP(5000),
378 }; 378 };
379 uint32_t fData[ARRAY]; 379 uint32_t fData[ARRAY];
380 bool fUsePortable; 380 bool fUsePortable;
381 381
382 public: 382 public:
383 CLZBench(void* param, bool usePortable) 383 CLZBench(void* param, bool usePortable)
384 : INHERITED(param) 384 : INHERITED(param)
385 , fUsePortable(usePortable) { 385 , fUsePortable(usePortable) {
386 386
387 SkMWCRandom rand; 387 SkRandom rand;
388 for (int i = 0; i < ARRAY; ++i) { 388 for (int i = 0; i < ARRAY; ++i) {
389 fData[i] = rand.nextU(); 389 fData[i] = rand.nextU();
390 } 390 }
391 391
392 if (fUsePortable) { 392 if (fUsePortable) {
393 fName = "clz_portable"; 393 fName = "clz_portable";
394 } else { 394 } else {
395 fName = "clz_intrinsic"; 395 fName = "clz_intrinsic";
396 } 396 }
397 fIsRendering = false; 397 fIsRendering = false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 enum { 437 enum {
438 ARRAY = SkBENCHLOOP(1000), 438 ARRAY = SkBENCHLOOP(1000),
439 LOOP = SkBENCHLOOP(1000), 439 LOOP = SkBENCHLOOP(1000),
440 }; 440 };
441 SkVector fVec[ARRAY]; 441 SkVector fVec[ARRAY];
442 442
443 public: 443 public:
444 NormalizeBench(void* param) 444 NormalizeBench(void* param)
445 : INHERITED(param) { 445 : INHERITED(param) {
446 446
447 SkMWCRandom rand; 447 SkRandom rand;
448 for (int i = 0; i < ARRAY; ++i) { 448 for (int i = 0; i < ARRAY; ++i) {
449 fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1()); 449 fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1());
450 } 450 }
451 451
452 fName = "point_normalize"; 452 fName = "point_normalize";
453 fIsRendering = false; 453 fIsRendering = false;
454 } 454 }
455 455
456 // just so the compiler doesn't remove our loops 456 // just so the compiler doesn't remove our loops
457 virtual void process(int) {} 457 virtual void process(int) {}
(...skipping 25 matching lines...) Expand all
483 class FixedMathBench : public SkBenchmark { 483 class FixedMathBench : public SkBenchmark {
484 enum { 484 enum {
485 N = SkBENCHLOOP(1000), 485 N = SkBENCHLOOP(1000),
486 NN = SkBENCHLOOP(1000), 486 NN = SkBENCHLOOP(1000),
487 }; 487 };
488 float fData[N]; 488 float fData[N];
489 SkFixed fResult[N]; 489 SkFixed fResult[N];
490 public: 490 public:
491 491
492 FixedMathBench(void* param) : INHERITED(param) { 492 FixedMathBench(void* param) : INHERITED(param) {
493 SkMWCRandom rand; 493 SkRandom rand;
494 for (int i = 0; i < N; ++i) { 494 for (int i = 0; i < N; ++i) {
495 fData[i] = rand.nextSScalar1(); 495 fData[i] = rand.nextSScalar1();
496 } 496 }
497 497
498 fIsRendering = false; 498 fIsRendering = false;
499 } 499 }
500 500
501 protected: 501 protected:
502 virtual void onDraw(SkCanvas*) { 502 virtual void onDraw(SkCanvas*) {
503 for (int j = 0; j < NN; ++j) { 503 for (int j = 0; j < NN; ++j) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 538
539 DEF_BENCH( return new FloorBench(p, false); ) 539 DEF_BENCH( return new FloorBench(p, false); )
540 DEF_BENCH( return new FloorBench(p, true); ) 540 DEF_BENCH( return new FloorBench(p, true); )
541 541
542 DEF_BENCH( return new CLZBench(p, false); ) 542 DEF_BENCH( return new CLZBench(p, false); )
543 DEF_BENCH( return new CLZBench(p, true); ) 543 DEF_BENCH( return new CLZBench(p, true); )
544 544
545 DEF_BENCH( return new NormalizeBench(p); ) 545 DEF_BENCH( return new NormalizeBench(p); )
546 546
547 DEF_BENCH( return new FixedMathBench(p); ) 547 DEF_BENCH( return new FixedMathBench(p); )
OLDNEW
« no previous file with comments | « bench/LineBench.cpp ('k') | bench/MatrixBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698