Index: bench/RTreeBench.cpp |
diff --git a/bench/RTreeBench.cpp b/bench/RTreeBench.cpp |
index 030d376017160ae740372e6a39168e46117b1a7a..93576a7fcfff4b774a04d8de51e10be393febd62 100644 |
--- a/bench/RTreeBench.cpp |
+++ b/bench/RTreeBench.cpp |
@@ -19,12 +19,10 @@ static const int GRID_WIDTH = 100; |
typedef SkRect (*MakeRectProc)(SkRandom&, int, int); |
-// Time how long it takes to build an R-Tree either bulk-loaded or not |
+// Time how long it takes to build an R-Tree. |
class RTreeBuildBench : public Benchmark { |
public: |
- RTreeBuildBench(const char* name, MakeRectProc proc, SkRTree* tree) |
- : fTree(tree) |
- , fProc(proc) { |
+ RTreeBuildBench(const char* name, MakeRectProc proc) : fProc(proc) { |
fName.printf("rtree_%s_build", name); |
} |
@@ -32,9 +30,6 @@ public: |
return backend == kNonRendering_Backend; |
} |
- virtual ~RTreeBuildBench() { |
- fTree->unref(); |
- } |
protected: |
virtual const char* onGetName() SK_OVERRIDE { |
return fName.c_str(); |
@@ -47,34 +42,27 @@ protected: |
} |
for (int i = 0; i < loops; ++i) { |
- fTree->insert(&rects, NUM_BUILD_RECTS); |
+ SkRTree tree; |
+ tree.insert(&rects, NUM_BUILD_RECTS); |
SkASSERT(rects != NULL); // It'd break this bench if the tree took ownership of rects. |
- fTree->clear(); |
} |
} |
private: |
- SkRTree* fTree; |
MakeRectProc fProc; |
SkString fName; |
typedef Benchmark INHERITED; |
}; |
-// Time how long it takes to perform queries on an R-Tree, bulk-loaded or not |
+// Time how long it takes to perform queries on an R-Tree. |
class RTreeQueryBench : public Benchmark { |
public: |
- RTreeQueryBench(const char* name, MakeRectProc proc, SkRTree* tree) |
- : fTree(tree) |
- , fProc(proc) { |
+ RTreeQueryBench(const char* name, MakeRectProc proc) : fProc(proc) { |
fName.printf("rtree_%s_query", name); |
} |
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
return backend == kNonRendering_Backend; |
} |
- |
- virtual ~RTreeQueryBench() { |
- fTree->unref(); |
- } |
protected: |
virtual const char* onGetName() SK_OVERRIDE { |
return fName.c_str(); |
@@ -85,7 +73,7 @@ protected: |
for (int i = 0; i < NUM_QUERY_RECTS; ++i) { |
rects[i] = fProc(rand, i, NUM_QUERY_RECTS); |
} |
- fTree->insert(&rects, NUM_QUERY_RECTS); |
+ fTree.insert(&rects, NUM_QUERY_RECTS); |
} |
virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
@@ -97,21 +85,16 @@ protected: |
query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS); |
query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2); |
query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2); |
- fTree->search(query, &hits); |
+ fTree.search(query, &hits); |
} |
} |
private: |
- SkBBoxHierarchy* fTree; |
+ SkRTree fTree; |
MakeRectProc fProc; |
SkString fName; |
typedef Benchmark INHERITED; |
}; |
-static inline SkRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) { |
- SkRect out = SkRect::MakeWH(SkIntToScalar(index+1), SkIntToScalar(index+1)); |
- return out; |
-} |
- |
static inline SkRect make_XYordered_rects(SkRandom& rand, int index, int numRects) { |
SkRect out; |
out.fLeft = SkIntToScalar(index % GRID_WIDTH); |
@@ -138,42 +121,18 @@ static inline SkRect make_random_rects(SkRandom& rand, int index, int numRects) |
return out; |
} |
+static inline SkRect make_concentric_rects(SkRandom&, int index, int numRects) { |
+ return SkRect::MakeWH(SkIntToScalar(index+1), SkIntToScalar(index+1)); |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("XY_sorted", &make_XYordered_rects, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("XY_unsorted", &make_XYordered_rects, SkRTree::Create(5, 16, 1, false)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("YX_sorted", &make_YXordered_rects, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("YX_unsorted", &make_YXordered_rects, SkRTree::Create(5, 16, 1, false)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("random_sorted", &make_random_rects, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("random_unsorted", &make_random_rects, SkRTree::Create(5, 16, 1, false)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("concentric_sorted", &make_concentric_rects_increasing, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, |
- ("concentric_unsorted", |
- &make_concentric_rects_increasing, |
- SkRTree::Create(5, 16, 1, false)));) |
- |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("XY_sorted", &make_XYordered_rects, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("XY_unsorted", &make_XYordered_rects, SkRTree::Create(5, 16, 1, false)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("YX_sorted", &make_YXordered_rects, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("YX_unsorted", &make_YXordered_rects, SkRTree::Create(5, 16, 1, false)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("random_sorted", &make_random_rects, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("random_unsorted", &make_random_rects, SkRTree::Create(5, 16, 1, false)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("concentric_sorted", &make_concentric_rects_increasing, SkRTree::Create(5, 16)));) |
-DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, |
- ("concentric_unsorted", |
- &make_concentric_rects_increasing, |
- SkRTree::Create(5, 16, 1, false)));) |
+DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("XY", &make_XYordered_rects))); |
+DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("YX", &make_YXordered_rects))); |
+DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("random", &make_random_rects))); |
+DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("concentric", &make_concentric_rects))); |
+ |
+DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("XY", &make_XYordered_rects))); |
+DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("YX", &make_YXordered_rects))); |
+DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("random", &make_random_rects))); |
+DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("concentric", &make_concentric_rects))); |