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

Side by Side Diff: bench/RTreeBench.cpp

Issue 913833002: Simplify SkBBH::insert API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | src/core/SkBBoxHierarchy.h » ('j') | 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 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"
(...skipping 25 matching lines...) Expand all
36 } 36 }
37 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 37 void onDraw(const int loops, SkCanvas* canvas) SK_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, 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) SK_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() SK_OVERRIDE {
68 return fName.c_str(); 68 return fName.c_str();
69 } 69 }
70 void onPreDraw() SK_OVERRIDE { 70 void onPreDraw() SK_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, 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) SK_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);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)));
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBBoxHierarchy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698