OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
9 #include "SkBenchmark.h" | 9 #include "SkBenchmark.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkRTree.h" | 11 #include "SkRTree.h" |
12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 | 14 |
15 // confine rectangles to a smallish area, so queries generally hit something, an d overlap occurs: | 15 // confine rectangles to a smallish area, so queries generally hit something, an d overlap occurs: |
16 static const int GENERATE_EXTENTS = 1000; | 16 static const int GENERATE_EXTENTS = 1000; |
17 static const int NUM_BUILD_RECTS = 500; | 17 static const int NUM_BUILD_RECTS = 500; |
18 static const int NUM_QUERY_RECTS = 5000; | 18 static const int NUM_QUERY_RECTS = 5000; |
19 static const int NUM_QUERIES = 1000; | 19 static const int NUM_QUERIES = 1000; |
20 static const int GRID_WIDTH = 100; | |
20 | 21 |
21 typedef SkIRect (*MakeRectProc)(SkMWCRandom&, int, int); | 22 typedef SkIRect (*MakeRectProc)(SkMWCRandom&, int, int); |
22 | 23 |
23 // Time how long it takes to build an R-Tree either bulk-loaded or not | 24 // Time how long it takes to build an R-Tree either bulk-loaded or not |
24 class BBoxBuildBench : public SkBenchmark { | 25 class BBoxBuildBench : public SkBenchmark { |
25 public: | 26 public: |
26 BBoxBuildBench(void* param, const char* name, MakeRectProc proc, bool bulkLo ad, | 27 BBoxBuildBench(void* param, const char* name, MakeRectProc proc, bool bulkLo ad, |
27 SkBBoxHierarchy* tree) | 28 SkBBoxHierarchy* tree) |
28 : INHERITED(param) | 29 : INHERITED(param) |
29 , fTree(tree) | 30 , fTree(tree) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 static inline SkIRect make_concentric_rects_increasing(SkMWCRandom&, int index, int numRects) { | 157 static inline SkIRect make_concentric_rects_increasing(SkMWCRandom&, int index, int numRects) { |
157 SkIRect out = {0, 0, index + 1, index + 1}; | 158 SkIRect out = {0, 0, index + 1, index + 1}; |
158 return out; | 159 return out; |
159 } | 160 } |
160 | 161 |
161 static inline SkIRect make_concentric_rects_decreasing(SkMWCRandom&, int index, int numRects) { | 162 static inline SkIRect make_concentric_rects_decreasing(SkMWCRandom&, int index, int numRects) { |
162 SkIRect out = {0, 0, numRects - index, numRects - index}; | 163 SkIRect out = {0, 0, numRects - index, numRects - index}; |
163 return out; | 164 return out; |
164 } | 165 } |
165 | 166 |
167 static inline SkIRect make_XYordered_rects(SkMWCRandom& rand, int index, int num Rects) { | |
168 SkIRect out; | |
169 out.fLeft = index % GRID_WIDTH; | |
170 out.fTop = index / GRID_WIDTH; | |
171 out.fRight = 1 + rand.nextU() % (GENERATE_EXTENTS / 3); | |
172 out.fBottom = 1 + rand.nextU() % (GENERATE_EXTENTS / 3); | |
caryclark
2013/08/29 19:22:18
this allows the right and bottom to be less than l
sglez
2013/08/29 20:17:38
Thanks
| |
173 return out; | |
174 } | |
175 static inline SkIRect make_YXordered_rects(SkMWCRandom& rand, int index, int num Rects) { | |
176 SkIRect out; | |
177 out.fLeft = index / GRID_WIDTH; | |
178 out.fTop = index % GRID_WIDTH; | |
179 out.fRight = 1 + rand.nextU() % (GENERATE_EXTENTS / 3); | |
180 out.fBottom = 1 + rand.nextU() % (GENERATE_EXTENTS / 3); | |
181 return out; | |
182 } | |
183 | |
166 static inline SkIRect make_point_rects(SkMWCRandom& rand, int index, int numRect s) { | 184 static inline SkIRect make_point_rects(SkMWCRandom& rand, int index, int numRect s) { |
167 SkIRect out; | 185 SkIRect out; |
168 out.fLeft = rand.nextU() % GENERATE_EXTENTS; | 186 out.fLeft = rand.nextU() % GENERATE_EXTENTS; |
169 out.fTop = rand.nextU() % GENERATE_EXTENTS; | 187 out.fTop = rand.nextU() % GENERATE_EXTENTS; |
170 out.fRight = out.fLeft + (GENERATE_EXTENTS / 200); | 188 out.fRight = out.fLeft + (GENERATE_EXTENTS / 200); |
171 out.fBottom = out.fTop + (GENERATE_EXTENTS / 200); | 189 out.fBottom = out.fTop + (GENERATE_EXTENTS / 200); |
172 return out; | 190 return out; |
173 } | 191 } |
174 | 192 |
175 static inline SkIRect make_random_rects(SkMWCRandom& rand, int index, int numRec ts) { | 193 static inline SkIRect make_random_rects(SkMWCRandom& rand, int index, int numRec ts) { |
(...skipping 10 matching lines...) Expand all Loading... | |
186 out.fLeft = rand.nextU() % GENERATE_EXTENTS; | 204 out.fLeft = rand.nextU() % GENERATE_EXTENTS; |
187 out.fTop = rand.nextU() % GENERATE_EXTENTS; | 205 out.fTop = rand.nextU() % GENERATE_EXTENTS; |
188 out.fRight = out.fLeft + (GENERATE_EXTENTS / 3); | 206 out.fRight = out.fLeft + (GENERATE_EXTENTS / 3); |
189 out.fBottom = out.fTop + (GENERATE_EXTENTS / 3); | 207 out.fBottom = out.fTop + (GENERATE_EXTENTS / 3); |
190 return out; | 208 return out; |
191 } | 209 } |
192 | 210 |
193 /////////////////////////////////////////////////////////////////////////////// | 211 /////////////////////////////////////////////////////////////////////////////// |
194 | 212 |
195 static inline SkBenchmark* Fact0(void* p) { | 213 static inline SkBenchmark* Fact0(void* p) { |
214 return SkNEW_ARGS(BBoxBuildBench, (p, "XYordered", &make_XYordered_rects, fa lse, | |
215 SkRTree::Create(5, 16))); | |
216 } | |
217 static inline SkBenchmark* Fact1(void* p) { | |
218 return SkNEW_ARGS(BBoxBuildBench, (p, "XYordered", &make_XYordered_rects, tr ue, | |
219 SkRTree::Create(5, 16))); | |
caryclark
2013/08/29 19:22:18
should the strings for Fact0 and Fact1 be differen
sglez
2013/08/29 20:17:38
They are the same, but the final bench name will b
| |
220 } | |
221 static inline SkBenchmark* Fact2(void* p) { | |
222 return SkNEW_ARGS(BBoxBuildBench, (p, "(unsorted)XYordered", &make_XYordered _rects, true, | |
223 SkRTree::Create(5, 16, 1, false))); | |
caryclark
2013/08/29 19:22:18
should the string passed to Fact2 and Fact4 be dif
sglez
2013/08/29 20:17:38
Same as before, but instead of appending _build it
| |
224 } | |
225 static inline SkBenchmark* Fact3(void* p) { | |
226 return SkNEW_ARGS(BBoxQueryBench, (p, "XYordered", &make_XYordered_rects, tr ue, | |
227 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)) ); | |
228 } | |
229 static inline SkBenchmark* Fact4(void* p) { | |
230 return SkNEW_ARGS(BBoxQueryBench, (p, "(unsorted)XYordered", &make_XYordered _rects, true, | |
231 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false))); | |
232 } | |
233 | |
234 static inline SkBenchmark* Fact5(void* p) { | |
235 return SkNEW_ARGS(BBoxBuildBench, (p, "YXordered", &make_YXordered_rects, fa lse, | |
236 SkRTree::Create(5, 16))); | |
237 } | |
238 static inline SkBenchmark* Fact6(void* p) { | |
239 return SkNEW_ARGS(BBoxBuildBench, (p, "YXordered", &make_YXordered_rects, tr ue, | |
240 SkRTree::Create(5, 16))); | |
241 } | |
242 static inline SkBenchmark* Fact7(void* p) { | |
243 return SkNEW_ARGS(BBoxBuildBench, (p, "(unsorted)YXordered", &make_YXordered _rects, true, | |
244 SkRTree::Create(5, 16, 1, false))); | |
245 } | |
246 static inline SkBenchmark* Fact8(void* p) { | |
247 return SkNEW_ARGS(BBoxQueryBench, (p, "YXordered", &make_YXordered_rects, tr ue, | |
248 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)) ); | |
249 } | |
250 static inline SkBenchmark* Fact9(void* p) { | |
251 return SkNEW_ARGS(BBoxQueryBench, (p, "(unsorted)YXordered", &make_YXordered _rects, true, | |
252 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false))); | |
253 } | |
254 | |
255 static inline SkBenchmark* Fact10(void* p) { | |
256 return SkNEW_ARGS(BBoxBuildBench, (p, "random", &make_random_rects, false, | |
257 SkRTree::Create(5, 16))); | |
258 } | |
259 static inline SkBenchmark* Fact11(void* p) { | |
196 return SkNEW_ARGS(BBoxBuildBench, (p, "random", &make_random_rects, true, | 260 return SkNEW_ARGS(BBoxBuildBench, (p, "random", &make_random_rects, true, |
197 SkRTree::Create(5, 16))); | 261 SkRTree::Create(5, 16))); |
198 } | 262 } |
199 static inline SkBenchmark* Fact1(void* p) { | 263 static inline SkBenchmark* Fact12(void* p) { |
200 return SkNEW_ARGS(BBoxBuildBench, (p, "random", &make_random_rects, false, | 264 return SkNEW_ARGS(BBoxBuildBench, (p, "(unsorted)random", &make_random_rects , true, |
201 SkRTree::Create(5, 16))); | 265 SkRTree::Create(5, 16, 1, false))); |
202 } | 266 } |
203 static inline SkBenchmark* Fact2(void* p) { | 267 static inline SkBenchmark* Fact13(void* p) { |
268 return SkNEW_ARGS(BBoxQueryBench, (p, "random", &make_random_rects, true, | |
269 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)) ); | |
270 } | |
271 static inline SkBenchmark* Fact14(void* p) { | |
272 return SkNEW_ARGS(BBoxQueryBench, (p, "(unsorted)random", &make_random_rects , true, | |
273 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false))); | |
274 } | |
275 | |
276 static inline SkBenchmark* Fact15(void* p) { | |
204 return SkNEW_ARGS(BBoxBuildBench, (p, "concentric", | 277 return SkNEW_ARGS(BBoxBuildBench, (p, "concentric", |
205 &make_concentric_rects_increasing, true, SkRTree::Create(5 , 16))); | 278 &make_concentric_rects_increasing, true, SkRTree::Create(5 , 16))); |
206 } | 279 } |
207 static inline SkBenchmark* Fact3(void* p) { | 280 static inline SkBenchmark* Fact16(void* p) { |
208 return SkNEW_ARGS(BBoxQueryBench, (p, "random", &make_random_rects, true, | 281 return SkNEW_ARGS(BBoxBuildBench, (p, "(unsorted)concentric", |
282 &make_concentric_rects_increasing, true, SkRTree::Create(5 , 16, 1, false))); | |
283 } | |
284 static inline SkBenchmark* Fact17(void* p) { | |
285 return SkNEW_ARGS(BBoxQueryBench, (p, "concentric", &make_concentric_rects_i ncreasing, true, | |
209 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)) ); | 286 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)) ); |
210 } | 287 } |
211 static inline SkBenchmark* Fact4(void* p) { | 288 static inline SkBenchmark* Fact18(void* p) { |
212 return SkNEW_ARGS(BBoxQueryBench, (p, "random", &make_random_rects, false, | 289 return SkNEW_ARGS(BBoxQueryBench, (p, "(unsorted)concentric", &make_concentr ic_rects_increasing, true, |
213 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)) ); | 290 BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false))); |
214 } | 291 } |
215 | 292 |
293 static BenchRegistry gReg18(Fact18); | |
294 static BenchRegistry gReg17(Fact17); | |
295 static BenchRegistry gReg16(Fact16); | |
296 static BenchRegistry gReg15(Fact15); | |
297 static BenchRegistry gReg14(Fact14); | |
298 static BenchRegistry gReg13(Fact13); | |
299 static BenchRegistry gReg12(Fact12); | |
300 static BenchRegistry gReg11(Fact11); | |
301 static BenchRegistry gReg10(Fact10); | |
302 static BenchRegistry gReg9(Fact9); | |
303 static BenchRegistry gReg8(Fact8); | |
304 static BenchRegistry gReg7(Fact7); | |
305 static BenchRegistry gReg6(Fact6); | |
306 static BenchRegistry gReg5(Fact5); | |
307 static BenchRegistry gReg4(Fact4); | |
308 static BenchRegistry gReg3(Fact3); | |
309 static BenchRegistry gReg2(Fact2); | |
310 static BenchRegistry gReg1(Fact1); | |
216 static BenchRegistry gReg0(Fact0); | 311 static BenchRegistry gReg0(Fact0); |
217 static BenchRegistry gReg1(Fact1); | 312 |
218 static BenchRegistry gReg2(Fact2); | |
219 static BenchRegistry gReg3(Fact3); | |
220 static BenchRegistry gReg4(Fact4); | |
OLD | NEW |