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

Side by Side Diff: bench/MatrixBench.cpp

Issue 23478013: Major bench refactoring. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: In debug, one loop only. 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
OLDNEW
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 "SkRandom.h" 10 #include "SkRandom.h"
11 #include "SkString.h" 11 #include "SkString.h"
12 12
13 class MatrixBench : public SkBenchmark { 13 class MatrixBench : public SkBenchmark {
14 SkString fName; 14 SkString fName;
15 enum { N = 100000 };
16 public: 15 public:
17 MatrixBench(void* param, const char name[]) : INHERITED(param) { 16 MatrixBench(void* param, const char name[]) : INHERITED(param) {
18 fName.printf("matrix_%s", name); 17 fName.printf("matrix_%s", name);
19 fIsRendering = false; 18 fIsRendering = false;
20 } 19 }
21 20
22 virtual void performTest() = 0; 21 virtual void performTest() = 0;
23 22
24 protected: 23 protected:
25 virtual int mulLoopCount() const { return 1; } 24 virtual int mulLoopCount() const { return 1; }
26 25
27 virtual const char* onGetName() { 26 virtual const char* onGetName() {
28 return fName.c_str(); 27 return fName.c_str();
29 } 28 }
30 29
31 virtual void onDraw(SkCanvas*) { 30 virtual void onDraw(SkCanvas*) {
32 int n = SkBENCHLOOP(N * this->mulLoopCount()); 31 for (int i = 0; i < this->getLoops(); i++) {
33 for (int i = 0; i < n; i++) {
34 this->performTest(); 32 this->performTest();
35 } 33 }
36 } 34 }
37 35
38 private: 36 private:
39 typedef SkBenchmark INHERITED; 37 typedef SkBenchmark INHERITED;
40 }; 38 };
41 39
42 // we want to stop the compiler from eliminating code that it thinks is a no-op 40 // we want to stop the compiler from eliminating code that it thinks is a no-op
43 // so we have a non-static global we increment, hoping that will convince the 41 // 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
289 float ty = fMatrix[SkMatrix::kMTransY]; 287 float ty = fMatrix[SkMatrix::kMTransY];
290 do { 288 do {
291 dst->fY = SkScalarMulAdd(src->fY, my, ty); 289 dst->fY = SkScalarMulAdd(src->fY, my, ty);
292 dst->fX = SkScalarMulAdd(src->fX, mx, tx); 290 dst->fX = SkScalarMulAdd(src->fX, mx, tx);
293 src += 1; 291 src += 1;
294 dst += 1; 292 dst += 1;
295 } while (--count); 293 } while (--count);
296 } 294 }
297 private: 295 private:
298 enum { 296 enum {
299 kCount = SkBENCHLOOP(16) 297 kCount = 16
300 }; 298 };
301 SkMatrix fMatrix; 299 SkMatrix fMatrix;
302 SkPoint fSrc [16]; 300 SkPoint fSrc [kCount];
303 SkPoint fDst [16]; 301 SkPoint fDst [kCount];
304 SkRandom fRandom; 302 SkRandom fRandom;
305 typedef MatrixBench INHERITED; 303 typedef MatrixBench INHERITED;
306 }; 304 };
307 305
308 class ScaleTransDoubleMatrixBench : public MatrixBench { 306 class ScaleTransDoubleMatrixBench : public MatrixBench {
309 public: 307 public:
310 ScaleTransDoubleMatrixBench(void* p) : INHERITED(p, "scaletrans_double") { 308 ScaleTransDoubleMatrixBench(void* p) : INHERITED(p, "scaletrans_double") {
311 init9(fMatrix); 309 init9(fMatrix);
312 int i; 310 int i;
313 for (i = 0; i < kCount; i++) { 311 for (i = 0; i < kCount; i++) {
(...skipping 15 matching lines...) Expand all
329 float ty = (float) fMatrix[SkMatrix::kMTransY]; 327 float ty = (float) fMatrix[SkMatrix::kMTransY];
330 do { 328 do {
331 dst->fY = src->fY * my + ty; 329 dst->fY = src->fY * my + ty;
332 dst->fX = src->fX * mx + tx; 330 dst->fX = src->fX * mx + tx;
333 src += 1; 331 src += 1;
334 dst += 1; 332 dst += 1;
335 } while (--count); 333 } while (--count);
336 } 334 }
337 private: 335 private:
338 enum { 336 enum {
339 kCount = SkBENCHLOOP(16) 337 kCount = 16
340 }; 338 };
341 double fMatrix [9]; 339 double fMatrix [9];
342 SkPoint fSrc [16]; 340 SkPoint fSrc [kCount];
343 SkPoint fDst [16]; 341 SkPoint fDst [kCount];
344 SkRandom fRandom; 342 SkRandom fRandom;
345 typedef MatrixBench INHERITED; 343 typedef MatrixBench INHERITED;
346 }; 344 };
347 345
348 class InvertMapRectMatrixBench : public MatrixBench { 346 class InvertMapRectMatrixBench : public MatrixBench {
349 public: 347 public:
350 InvertMapRectMatrixBench(void* param, const char* name, int flags) 348 InvertMapRectMatrixBench(void* param, const char* name, int flags)
351 : INHERITED(param, name) 349 : INHERITED(param, name)
352 , fFlags(flags) { 350 , fFlags(flags) {
353 fMatrix.reset(); 351 fMatrix.reset();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 435
438 DEF_BENCH( return new InvertMapRectMatrixBench(p, 436 DEF_BENCH( return new InvertMapRectMatrixBench(p,
439 "invert_maprect_typemask_nonpersp", 437 "invert_maprect_typemask_nonpersp",
440 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | 438 InvertMapRectMatrixBench::kUncachedTypeMask_Flag |
441 InvertMapRectMatrixBench::kScale_Flag | 439 InvertMapRectMatrixBench::kScale_Flag |
442 InvertMapRectMatrixBench::kRotate_Flag | 440 InvertMapRectMatrixBench::kRotate_Flag |
443 InvertMapRectMatrixBench::kTranslate_Flag); ) 441 InvertMapRectMatrixBench::kTranslate_Flag); )
444 442
445 DEF_BENCH( return new ScaleTransMixedMatrixBench(p); ) 443 DEF_BENCH( return new ScaleTransMixedMatrixBench(p); )
446 DEF_BENCH( return new ScaleTransDoubleMatrixBench(p); ) 444 DEF_BENCH( return new ScaleTransDoubleMatrixBench(p); )
OLDNEW
« no previous file with comments | « bench/Matrix44Bench.cpp ('k') | bench/MatrixConvolutionBench.cpp » ('j') | bench/benchmain.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698