OLD | NEW |
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 public: | 136 public: |
137 UniquePaintDictionaryRecordBench(void* param) | 137 UniquePaintDictionaryRecordBench(void* param) |
138 : INHERITED(param, "unique_paint_dictionary") { } | 138 : INHERITED(param, "unique_paint_dictionary") { } |
139 | 139 |
140 enum { | 140 enum { |
141 M = SkBENCHLOOP(15000), // number of unique paint objects | 141 M = SkBENCHLOOP(15000), // number of unique paint objects |
142 }; | 142 }; |
143 protected: | 143 protected: |
144 virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; } | 144 virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; } |
145 virtual void recordCanvas(SkCanvas* canvas) { | 145 virtual void recordCanvas(SkCanvas* canvas) { |
146 SkMWCRandom rand; | 146 SkRandom rand; |
147 for (int i = 0; i < M; i++) { | 147 for (int i = 0; i < M; i++) { |
148 SkPaint paint; | 148 SkPaint paint; |
149 paint.setColor(rand.nextU()); | 149 paint.setColor(rand.nextU()); |
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 * | 161 * |
162 * Re-creating the paint objects in the inner loop slows the benchmark down 10%
. | 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 | 163 * Using setColor(i % objCount) instead of a random color creates a very high r
ate |
164 * of hash conflicts, slowing us down 12%. | 164 * of hash conflicts, slowing us down 12%. |
165 */ | 165 */ |
166 class RecurringPaintDictionaryRecordBench : public PictureRecordBench { | 166 class RecurringPaintDictionaryRecordBench : public PictureRecordBench { |
167 public: | 167 public: |
168 RecurringPaintDictionaryRecordBench(void* param) | 168 RecurringPaintDictionaryRecordBench(void* param) |
169 : INHERITED(param, "recurring_paint_dictionary") { | 169 : INHERITED(param, "recurring_paint_dictionary") { |
170 SkMWCRandom rand; | 170 SkRandom rand; |
171 for (int i = 0; i < ObjCount; i++) { | 171 for (int i = 0; i < ObjCount; i++) { |
172 fPaint[i].setColor(rand.nextU()); | 172 fPaint[i].setColor(rand.nextU()); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 enum { | 176 enum { |
177 ObjCount = 100, // number of unique paint objects | 177 ObjCount = 100, // number of unique paint objects |
178 M = SkBENCHLOOP(50000), // number of draw iterations | 178 M = SkBENCHLOOP(50000), // number of draw iterations |
179 }; | 179 }; |
180 protected: | 180 protected: |
(...skipping 12 matching lines...) Expand all Loading... |
193 | 193 |
194 /////////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////////// |
195 | 195 |
196 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); } | 196 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); } |
197 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench
(p); } | 197 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench
(p); } |
198 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe
nch(p); } | 198 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe
nch(p); } |
199 | 199 |
200 static BenchRegistry gReg0(Fact0); | 200 static BenchRegistry gReg0(Fact0); |
201 static BenchRegistry gReg1(Fact1); | 201 static BenchRegistry gReg1(Fact1); |
202 static BenchRegistry gReg2(Fact2); | 202 static BenchRegistry gReg2(Fact2); |
OLD | NEW |