OLD | NEW |
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 enum { N = 100000 }; | |
17 public: | 16 public: |
18 ScalarBench(void* param, const char name[]) : INHERITED(param) { | 17 ScalarBench(void* param, const char name[]) : INHERITED(param) { |
19 fName.printf("scalar_%s", name); | 18 fName.printf("scalar_%s", name); |
20 fIsRendering = false; | 19 fIsRendering = false; |
21 } | 20 } |
22 | 21 |
23 virtual void performTest() = 0; | 22 virtual void performTest() = 0; |
24 | 23 |
25 protected: | 24 protected: |
26 virtual int mulLoopCount() const { return 1; } | 25 virtual int mulLoopCount() const { return 1; } |
27 | 26 |
28 virtual const char* onGetName() SK_OVERRIDE { | 27 virtual const char* onGetName() SK_OVERRIDE { |
29 return fName.c_str(); | 28 return fName.c_str(); |
30 } | 29 } |
31 | 30 |
32 virtual void onDraw(SkCanvas* canvas) { | 31 virtual void onDraw(SkCanvas* canvas) { |
33 int n = SkBENCHLOOP(N * this->mulLoopCount()); | 32 for (int i = 0; i < this->getLoops(); i++) { |
34 for (int i = 0; i < n; i++) { | |
35 this->performTest(); | 33 this->performTest(); |
36 } | 34 } |
37 } | 35 } |
38 | 36 |
39 private: | 37 private: |
40 typedef SkBenchmark INHERITED; | 38 typedef SkBenchmark INHERITED; |
41 }; | 39 }; |
42 | 40 |
43 // we want to stop the compiler from eliminating code that it thinks is a no-op | 41 // we want to stop the compiler from eliminating code that it thinks is a no-op |
44 // so we have a non-static global we increment, hoping that will convince the | 42 // so we have a non-static global we increment, hoping that will convince the |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 SkScalar fArray[ARRAY_N]; | 126 SkScalar fArray[ARRAY_N]; |
129 | 127 |
130 typedef ScalarBench INHERITED; | 128 typedef ScalarBench INHERITED; |
131 }; | 129 }; |
132 | 130 |
133 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
134 | 132 |
135 class RectBoundsBench : public SkBenchmark { | 133 class RectBoundsBench : public SkBenchmark { |
136 enum { | 134 enum { |
137 PTS = 100, | 135 PTS = 100, |
138 N = SkBENCHLOOP(10000) | |
139 }; | 136 }; |
140 SkPoint fPts[PTS]; | 137 SkPoint fPts[PTS]; |
141 | 138 |
142 public: | 139 public: |
143 RectBoundsBench(void* param) : INHERITED(param) { | 140 RectBoundsBench(void* param) : INHERITED(param) { |
144 SkRandom rand; | 141 SkRandom rand; |
145 for (int i = 0; i < PTS; ++i) { | 142 for (int i = 0; i < PTS; ++i) { |
146 fPts[i].fX = rand.nextSScalar1(); | 143 fPts[i].fX = rand.nextSScalar1(); |
147 fPts[i].fY = rand.nextSScalar1(); | 144 fPts[i].fY = rand.nextSScalar1(); |
148 } | 145 } |
149 fIsRendering = false; | 146 fIsRendering = false; |
150 } | 147 } |
151 | 148 |
152 protected: | 149 protected: |
153 virtual const char* onGetName() SK_OVERRIDE { | 150 virtual const char* onGetName() SK_OVERRIDE { |
154 return "rect_bounds"; | 151 return "rect_bounds"; |
155 } | 152 } |
156 | 153 |
157 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 154 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
158 SkRect r; | 155 SkRect r; |
159 for (int i = 0; i < N; ++i) { | 156 for (int i = 0; i < this->getLoops(); ++i) { |
160 r.set(fPts, PTS); | 157 r.set(fPts, PTS); |
161 } | 158 } |
162 } | 159 } |
163 | 160 |
164 private: | 161 private: |
165 typedef SkBenchmark INHERITED; | 162 typedef SkBenchmark INHERITED; |
166 }; | 163 }; |
167 | 164 |
168 /////////////////////////////////////////////////////////////////////////////// | 165 /////////////////////////////////////////////////////////////////////////////// |
169 | 166 |
170 static SkBenchmark* S0(void* p) { return new FloatComparisonBench(p); } | 167 static SkBenchmark* S0(void* p) { return new FloatComparisonBench(p); } |
171 static SkBenchmark* S1(void* p) { return new ForcedIntComparisonBench(p); } | 168 static SkBenchmark* S1(void* p) { return new ForcedIntComparisonBench(p); } |
172 static SkBenchmark* S2(void* p) { return new RectBoundsBench(p); } | 169 static SkBenchmark* S2(void* p) { return new RectBoundsBench(p); } |
173 static SkBenchmark* S3(void* p) { return new IsFiniteScalarBench(p); } | 170 static SkBenchmark* S3(void* p) { return new IsFiniteScalarBench(p); } |
174 | 171 |
175 static BenchRegistry gReg0(S0); | 172 static BenchRegistry gReg0(S0); |
176 static BenchRegistry gReg1(S1); | 173 static BenchRegistry gReg1(S1); |
177 static BenchRegistry gReg2(S2); | 174 static BenchRegistry gReg2(S2); |
178 static BenchRegistry gReg3(S3); | 175 static BenchRegistry gReg3(S3); |
OLD | NEW |