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

Side by Side Diff: bench/PictureRecordBench.cpp

Issue 18119011: Streamline picture_record_recurring_ bench. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | « no previous file | no next file » | 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 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkBenchmark.h" 7 #include "SkBenchmark.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 canvas->drawPaint(paint); 150 canvas->drawPaint(paint);
151 } 151 }
152 } 152 }
153 153
154 private: 154 private:
155 typedef PictureRecordBench INHERITED; 155 typedef PictureRecordBench INHERITED;
156 }; 156 };
157 157
158 /* 158 /*
159 * Populates the SkPaint dictionary with a number of unique paint 159 * Populates the SkPaint dictionary with a number of unique paint
160 * objects that get reused repeatedly 160 * objects that get reused repeatedly.
161 *
162 * Re-creating the paint objects in the inner loop slows the benchmark down 10% .
163 * Using setColor(i % objCount) instead of a random color creates a very high r ate
164 * of hash conflicts, slowing us down 12%.
161 */ 165 */
162 class RecurringPaintDictionaryRecordBench : public PictureRecordBench { 166 class RecurringPaintDictionaryRecordBench : public PictureRecordBench {
163 public: 167 public:
164 RecurringPaintDictionaryRecordBench(void* param) 168 RecurringPaintDictionaryRecordBench(void* param)
165 : INHERITED(param, "recurring_paint_dictionary") { } 169 : INHERITED(param, "recurring_paint_dictionary") {
170 SkRandom rand;
171 for (int i = 0; i < ObjCount; i++) {
172 fPaint[i].setColor(rand.nextU());
173 }
174 }
166 175
167 enum { 176 enum {
168 ObjCount = 100, // number of unique paint objects 177 ObjCount = 100, // number of unique paint objects
169 M = SkBENCHLOOP(50000), // number of draw iterations 178 M = SkBENCHLOOP(50000), // number of draw iterations
170 }; 179 };
171 protected: 180 protected:
172 virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; } 181 virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; }
173 virtual void recordCanvas(SkCanvas* canvas) { 182 virtual void recordCanvas(SkCanvas* canvas) {
174 183
175 for (int i = 0; i < M; i++) { 184 for (int i = 0; i < M; i++) {
176 SkPaint paint; 185 canvas->drawPaint(fPaint[i % ObjCount]);
177 paint.setColor(i % ObjCount);
178 canvas->drawPaint(paint);
179 } 186 }
180 } 187 }
181 188
182 private: 189 private:
190 SkPaint fPaint [ObjCount];
183 typedef PictureRecordBench INHERITED; 191 typedef PictureRecordBench INHERITED;
184 }; 192 };
185 193
186 /////////////////////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////////////////////
187 195
188 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); } 196 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); }
189 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench (p); } 197 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench (p); }
190 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe nch(p); } 198 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe nch(p); }
191 199
192 static BenchRegistry gReg0(Fact0); 200 static BenchRegistry gReg0(Fact0);
193 static BenchRegistry gReg1(Fact1); 201 static BenchRegistry gReg1(Fact1);
194 static BenchRegistry gReg2(Fact2); 202 static BenchRegistry gReg2(Fact2);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698