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

Side by Side Diff: bench/ScalarBench.cpp

Issue 23876006: Refactoring: get rid of the SkBenchmark void* parameter. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: sync to head 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/RepeatTileBench.cpp ('k') | bench/ShaderMaskBench.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 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 "SkFloatBits.h" 9 #include "SkFloatBits.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 #include "SkRect.h" 11 #include "SkRect.h"
12 #include "SkString.h" 12 #include "SkString.h"
13 13
14 class ScalarBench : public SkBenchmark { 14 class ScalarBench : public SkBenchmark {
15 SkString fName; 15 SkString fName;
16 public: 16 public:
17 ScalarBench(void* param, const char name[]) : INHERITED(param) { 17 ScalarBench(const char name[]) {
18 fName.printf("scalar_%s", name); 18 fName.printf("scalar_%s", name);
19 fIsRendering = false; 19 fIsRendering = false;
20 } 20 }
21 21
22 virtual void performTest() = 0; 22 virtual void performTest() = 0;
23 23
24 protected: 24 protected:
25 virtual int mulLoopCount() const { return 1; } 25 virtual int mulLoopCount() const { return 1; }
26 26
27 virtual const char* onGetName() SK_OVERRIDE { 27 virtual const char* onGetName() SK_OVERRIDE {
(...skipping 27 matching lines...) Expand all
55 // reasonable values in our arrays. 55 // reasonable values in our arrays.
56 template <typename T> void init9(T array[9]) { 56 template <typename T> void init9(T array[9]) {
57 SkRandom rand; 57 SkRandom rand;
58 for (int i = 0; i < 9; i++) { 58 for (int i = 0; i < 9; i++) {
59 array[i] = rand.nextSScalar1(); 59 array[i] = rand.nextSScalar1();
60 } 60 }
61 } 61 }
62 62
63 class FloatComparisonBench : public ScalarBench { 63 class FloatComparisonBench : public ScalarBench {
64 public: 64 public:
65 FloatComparisonBench(void* param) : INHERITED(param, "compare_float") { 65 FloatComparisonBench() : INHERITED("compare_float") {
66 init9(fArray); 66 init9(fArray);
67 } 67 }
68 protected: 68 protected:
69 virtual int mulLoopCount() const { return 4; } 69 virtual int mulLoopCount() const { return 4; }
70 virtual void performTest() { 70 virtual void performTest() {
71 always_do(fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f); 71 always_do(fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f);
72 always_do(fArray[2] != 0.0f || fArray[5] != 0.0f); 72 always_do(fArray[2] != 0.0f || fArray[5] != 0.0f);
73 } 73 }
74 private: 74 private:
75 float fArray[9]; 75 float fArray[9];
76 typedef ScalarBench INHERITED; 76 typedef ScalarBench INHERITED;
77 }; 77 };
78 78
79 class ForcedIntComparisonBench : public ScalarBench { 79 class ForcedIntComparisonBench : public ScalarBench {
80 public: 80 public:
81 ForcedIntComparisonBench(void* param) 81 ForcedIntComparisonBench()
82 : INHERITED(param, "compare_forced_int") { 82 : INHERITED("compare_forced_int") {
83 init9(fArray); 83 init9(fArray);
84 } 84 }
85 protected: 85 protected:
86 virtual int mulLoopCount() const { return 4; } 86 virtual int mulLoopCount() const { return 4; }
87 virtual void performTest() { 87 virtual void performTest() {
88 always_do(SkScalarAs2sCompliment(fArray[6]) | 88 always_do(SkScalarAs2sCompliment(fArray[6]) |
89 SkScalarAs2sCompliment(fArray[7]) | 89 SkScalarAs2sCompliment(fArray[7]) |
90 (SkScalarAs2sCompliment(fArray[8]) - kPersp1Int)); 90 (SkScalarAs2sCompliment(fArray[8]) - kPersp1Int));
91 always_do(SkScalarAs2sCompliment(fArray[2]) | 91 always_do(SkScalarAs2sCompliment(fArray[2]) |
92 SkScalarAs2sCompliment(fArray[5])); 92 SkScalarAs2sCompliment(fArray[5]));
93 } 93 }
94 private: 94 private:
95 static const int32_t kPersp1Int = 0x3f800000; 95 static const int32_t kPersp1Int = 0x3f800000;
96 SkScalar fArray[9]; 96 SkScalar fArray[9];
97 typedef ScalarBench INHERITED; 97 typedef ScalarBench INHERITED;
98 }; 98 };
99 99
100 class IsFiniteScalarBench : public ScalarBench { 100 class IsFiniteScalarBench : public ScalarBench {
101 public: 101 public:
102 IsFiniteScalarBench(void* param) : INHERITED(param, "isfinite") { 102 IsFiniteScalarBench() : INHERITED("isfinite") {
103 SkRandom rand; 103 SkRandom rand;
104 for (size_t i = 0; i < ARRAY_N; ++i) { 104 for (size_t i = 0; i < ARRAY_N; ++i) {
105 fArray[i] = rand.nextSScalar1(); 105 fArray[i] = rand.nextSScalar1();
106 } 106 }
107 } 107 }
108 protected: 108 protected:
109 virtual int mulLoopCount() const { return 1; } 109 virtual int mulLoopCount() const { return 1; }
110 virtual void performTest() SK_OVERRIDE { 110 virtual void performTest() SK_OVERRIDE {
111 int sum = 0; 111 int sum = 0;
112 for (size_t i = 0; i < ARRAY_N; ++i) { 112 for (size_t i = 0; i < ARRAY_N; ++i) {
(...skipping 17 matching lines...) Expand all
130 130
131 /////////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////////
132 132
133 class RectBoundsBench : public SkBenchmark { 133 class RectBoundsBench : public SkBenchmark {
134 enum { 134 enum {
135 PTS = 100, 135 PTS = 100,
136 }; 136 };
137 SkPoint fPts[PTS]; 137 SkPoint fPts[PTS];
138 138
139 public: 139 public:
140 RectBoundsBench(void* param) : INHERITED(param) { 140 RectBoundsBench() {
141 SkRandom rand; 141 SkRandom rand;
142 for (int i = 0; i < PTS; ++i) { 142 for (int i = 0; i < PTS; ++i) {
143 fPts[i].fX = rand.nextSScalar1(); 143 fPts[i].fX = rand.nextSScalar1();
144 fPts[i].fY = rand.nextSScalar1(); 144 fPts[i].fY = rand.nextSScalar1();
145 } 145 }
146 fIsRendering = false; 146 fIsRendering = false;
147 } 147 }
148 148
149 protected: 149 protected:
150 virtual const char* onGetName() SK_OVERRIDE { 150 virtual const char* onGetName() SK_OVERRIDE {
151 return "rect_bounds"; 151 return "rect_bounds";
152 } 152 }
153 153
154 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 154 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
155 SkRect r; 155 SkRect r;
156 for (int i = 0; i < this->getLoops(); ++i) { 156 for (int i = 0; i < this->getLoops(); ++i) {
157 r.set(fPts, PTS); 157 r.set(fPts, PTS);
158 } 158 }
159 } 159 }
160 160
161 private: 161 private:
162 typedef SkBenchmark INHERITED; 162 typedef SkBenchmark INHERITED;
163 }; 163 };
164 164
165 /////////////////////////////////////////////////////////////////////////////// 165 ///////////////////////////////////////////////////////////////////////////////
166 166
167 static SkBenchmark* S0(void* p) { return new FloatComparisonBench(p); } 167 DEF_BENCH( return new FloatComparisonBench(); )
168 static SkBenchmark* S1(void* p) { return new ForcedIntComparisonBench(p); } 168 DEF_BENCH( return new ForcedIntComparisonBench(); )
169 static SkBenchmark* S2(void* p) { return new RectBoundsBench(p); } 169 DEF_BENCH( return new RectBoundsBench(); )
170 static SkBenchmark* S3(void* p) { return new IsFiniteScalarBench(p); } 170 DEF_BENCH( return new IsFiniteScalarBench(); )
171
172 static BenchRegistry gReg0(S0);
173 static BenchRegistry gReg1(S1);
174 static BenchRegistry gReg2(S2);
175 static BenchRegistry gReg3(S3);
OLDNEW
« no previous file with comments | « bench/RepeatTileBench.cpp ('k') | bench/ShaderMaskBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698