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

Side by Side Diff: bench/RegionBench.cpp

Issue 640723004: cleanup and optimize rect intersect routines (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup the new bench Created 6 years, 2 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 | « bench/GeometryBench.cpp ('k') | gyp/bench.gypi » ('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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 #include "SkRegion.h" 10 #include "SkRegion.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 Proc proc = fProc; 110 Proc proc = fProc;
111 for (int i = 0; i < loops; ++i) { 111 for (int i = 0; i < loops; ++i) {
112 proc(fA, fB); 112 proc(fA, fB);
113 } 113 }
114 } 114 }
115 115
116 private: 116 private:
117 typedef Benchmark INHERITED; 117 typedef Benchmark INHERITED;
118 }; 118 };
119 119
120 class RectSectBench : public Benchmark {
121 enum {
122 N = 1000
123 };
124 SkRect fArray0[N];
125 SkRect fArray1[N];
126 SkString fName;
127 bool fNewWay;
128
129 public:
130 static void RandRect(SkRect* r, SkRandom& rand) {
131 r->set(rand.nextSScalar1(), rand.nextSScalar1(),
132 rand.nextSScalar1(), rand.nextSScalar1());
133 r->sort();
134 }
135
136 RectSectBench(bool newWay) : fNewWay(newWay) {
137 fName.printf("rect_intersect_%s", newWay ? "new" : "old");
138
139 SkRandom rand;
140 for (int i = 0; i < N; i++) {
141 RandRect(&fArray0[i], rand);
142 RandRect(&fArray1[i], rand);
143 }
144 }
145
146 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
147 return backend == kNonRendering_Backend;
148 }
149
150 protected:
151 virtual const char* onGetName() { return fName.c_str(); }
152
153 virtual void onDraw(const int loops, SkCanvas* canvas) {
154 for (int i = 0; i < loops; ++i) {
155 if (fNewWay) {
156 for (int j = 0; j < N; ++j) {
157 SkRect r = fArray0[j];
158 r.intersect2(fArray1[j]);
159 }
160 } else {
161 for (int j = 0; j < N; ++j) {
162 SkRect r = fArray0[j];
163 r.intersect(fArray1[j]);
164 }
165 }
166 }
167 }
168
169 private:
170 typedef Benchmark INHERITED;
171 };
172
173 /////////////////////////////////////////////////////////////////////////////// 120 ///////////////////////////////////////////////////////////////////////////////
174 121
175 #define SMALL 16 122 #define SMALL 16
176 123
177 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, union_proc, "union")); ) 124 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, union_proc, "union")); )
178 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sect_proc, "intersect")); ) 125 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sect_proc, "intersect")); )
179 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diff_proc, "difference")); ) 126 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diff_proc, "difference")); )
180 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrect_proc, "differencerect ")); ) 127 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrect_proc, "differencerect ")); )
181 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrectbig_proc, "differencer ectbig")); ) 128 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrectbig_proc, "differencer ectbig")); )
182 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsrect_proc, "containsre ct")); ) 129 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsrect_proc, "containsre ct")); )
183 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrgn_proc, "intersectsrgn" )); ) 130 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrgn_proc, "intersectsrgn" )); )
184 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrect_proc, "intersectsrec t")); ) 131 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrect_proc, "intersectsrec t")); )
185 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsxy_proc, "containsxy") ); ) 132 DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsxy_proc, "containsxy") ); )
186
187 DEF_BENCH( return SkNEW_ARGS(RectSectBench, (false)); )
188 DEF_BENCH( return SkNEW_ARGS(RectSectBench, (true)); )
OLDNEW
« no previous file with comments | « bench/GeometryBench.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698