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 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkRTree.h" | 10 #include "SkRTree.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 | 13 |
14 // confine rectangles to a smallish area, so queries generally hit something, an
d overlap occurs: | 14 // confine rectangles to a smallish area, so queries generally hit something, an
d overlap occurs: |
15 static const SkScalar GENERATE_EXTENTS = 1000.0f; | 15 static const SkScalar GENERATE_EXTENTS = 1000.0f; |
16 static const int NUM_BUILD_RECTS = 500; | 16 static const int NUM_BUILD_RECTS = 500; |
17 static const int NUM_QUERY_RECTS = 5000; | 17 static const int NUM_QUERY_RECTS = 5000; |
18 static const int GRID_WIDTH = 100; | 18 static const int GRID_WIDTH = 100; |
19 | 19 |
20 typedef SkRect (*MakeRectProc)(SkRandom&, int, int); | 20 typedef SkRect (*MakeRectProc)(SkRandom&, int, int); |
21 | 21 |
22 // Time how long it takes to build an R-Tree. | 22 // Time how long it takes to build an R-Tree. |
23 class RTreeBuildBench : public Benchmark { | 23 class RTreeBuildBench : public Benchmark { |
24 public: | 24 public: |
25 RTreeBuildBench(const char* name, MakeRectProc proc) : fProc(proc) { | 25 RTreeBuildBench(const char* name, MakeRectProc proc) : fProc(proc) { |
26 fName.printf("rtree_%s_build", name); | 26 fName.printf("rtree_%s_build", name); |
27 } | 27 } |
28 | 28 |
29 bool isSuitableFor(Backend backend) SK_OVERRIDE { | 29 bool isSuitableFor(Backend backend) override { |
30 return backend == kNonRendering_Backend; | 30 return backend == kNonRendering_Backend; |
31 } | 31 } |
32 | 32 |
33 protected: | 33 protected: |
34 const char* onGetName() SK_OVERRIDE { | 34 const char* onGetName() override { |
35 return fName.c_str(); | 35 return fName.c_str(); |
36 } | 36 } |
37 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 37 void onDraw(const int loops, SkCanvas* canvas) override { |
38 SkRandom rand; | 38 SkRandom rand; |
39 SkAutoTMalloc<SkRect> rects(NUM_BUILD_RECTS); | 39 SkAutoTMalloc<SkRect> rects(NUM_BUILD_RECTS); |
40 for (int i = 0; i < NUM_BUILD_RECTS; ++i) { | 40 for (int i = 0; i < NUM_BUILD_RECTS; ++i) { |
41 rects[i] = fProc(rand, i, NUM_BUILD_RECTS); | 41 rects[i] = fProc(rand, i, NUM_BUILD_RECTS); |
42 } | 42 } |
43 | 43 |
44 for (int i = 0; i < loops; ++i) { | 44 for (int i = 0; i < loops; ++i) { |
45 SkRTree tree; | 45 SkRTree tree; |
46 tree.insert(rects.get(), NUM_BUILD_RECTS); | 46 tree.insert(rects.get(), NUM_BUILD_RECTS); |
47 SkASSERT(rects != NULL); // It'd break this bench if the tree took
ownership of rects. | 47 SkASSERT(rects != NULL); // It'd break this bench if the tree took
ownership of rects. |
48 } | 48 } |
49 } | 49 } |
50 private: | 50 private: |
51 MakeRectProc fProc; | 51 MakeRectProc fProc; |
52 SkString fName; | 52 SkString fName; |
53 typedef Benchmark INHERITED; | 53 typedef Benchmark INHERITED; |
54 }; | 54 }; |
55 | 55 |
56 // Time how long it takes to perform queries on an R-Tree. | 56 // Time how long it takes to perform queries on an R-Tree. |
57 class RTreeQueryBench : public Benchmark { | 57 class RTreeQueryBench : public Benchmark { |
58 public: | 58 public: |
59 RTreeQueryBench(const char* name, MakeRectProc proc) : fProc(proc) { | 59 RTreeQueryBench(const char* name, MakeRectProc proc) : fProc(proc) { |
60 fName.printf("rtree_%s_query", name); | 60 fName.printf("rtree_%s_query", name); |
61 } | 61 } |
62 | 62 |
63 bool isSuitableFor(Backend backend) SK_OVERRIDE { | 63 bool isSuitableFor(Backend backend) override { |
64 return backend == kNonRendering_Backend; | 64 return backend == kNonRendering_Backend; |
65 } | 65 } |
66 protected: | 66 protected: |
67 const char* onGetName() SK_OVERRIDE { | 67 const char* onGetName() override { |
68 return fName.c_str(); | 68 return fName.c_str(); |
69 } | 69 } |
70 void onPreDraw() SK_OVERRIDE { | 70 void onPreDraw() override { |
71 SkRandom rand; | 71 SkRandom rand; |
72 SkAutoTMalloc<SkRect> rects(NUM_QUERY_RECTS); | 72 SkAutoTMalloc<SkRect> rects(NUM_QUERY_RECTS); |
73 for (int i = 0; i < NUM_QUERY_RECTS; ++i) { | 73 for (int i = 0; i < NUM_QUERY_RECTS; ++i) { |
74 rects[i] = fProc(rand, i, NUM_QUERY_RECTS); | 74 rects[i] = fProc(rand, i, NUM_QUERY_RECTS); |
75 } | 75 } |
76 fTree.insert(rects.get(), NUM_QUERY_RECTS); | 76 fTree.insert(rects.get(), NUM_QUERY_RECTS); |
77 } | 77 } |
78 | 78 |
79 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 79 void onDraw(const int loops, SkCanvas* canvas) override { |
80 SkRandom rand; | 80 SkRandom rand; |
81 for (int i = 0; i < loops; ++i) { | 81 for (int i = 0; i < loops; ++i) { |
82 SkTDArray<unsigned> hits; | 82 SkTDArray<unsigned> hits; |
83 SkRect query; | 83 SkRect query; |
84 query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS); | 84 query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS); |
85 query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS); | 85 query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS); |
86 query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENT
S/2); | 86 query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENT
S/2); |
87 query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENT
S/2); | 87 query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENT
S/2); |
88 fTree.search(query, &hits); | 88 fTree.search(query, &hits); |
89 } | 89 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("XY", &make_XYordered_rect
s))); | 130 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("XY", &make_XYordered_rect
s))); |
131 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("YX", &make_YXordered_rect
s))); | 131 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("YX", &make_YXordered_rect
s))); |
132 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("random", &make_random_rects))
); | 132 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("random", &make_random_rects))
); |
133 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("concentric", &make_concentric_rec
ts))); | 133 DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("concentric", &make_concentric_rec
ts))); |
134 | 134 |
135 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("XY", &make_XYordered_rect
s))); | 135 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("XY", &make_XYordered_rect
s))); |
136 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("YX", &make_YXordered_rect
s))); | 136 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("YX", &make_YXordered_rect
s))); |
137 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("random", &make_random_rects))
); | 137 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("random", &make_random_rects))
); |
138 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("concentric", &make_concentric_rec
ts))); | 138 DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("concentric", &make_concentric_rec
ts))); |
OLD | NEW |