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

Side by Side Diff: bench/RefCntBench.cpp

Issue 1379923005: Remove const from `const int loops`. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: n too Created 5 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/RectoriBench.cpp ('k') | bench/RegionBench.cpp » ('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 #include <memory> 7 #include <memory>
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkAtomics.h" 9 #include "SkAtomics.h"
10 #include "SkRefCnt.h" 10 #include "SkRefCnt.h"
11 #include "SkWeakRefCnt.h" 11 #include "SkWeakRefCnt.h"
12 12
13 enum { 13 enum {
14 M = 2 14 M = 2
15 }; 15 };
16 16
17 class AtomicInc32 : public Benchmark { 17 class AtomicInc32 : public Benchmark {
18 public: 18 public:
19 AtomicInc32() : fX(0) {} 19 AtomicInc32() : fX(0) {}
20 20
21 bool isSuitableFor(Backend backend) override { 21 bool isSuitableFor(Backend backend) override {
22 return backend == kNonRendering_Backend; 22 return backend == kNonRendering_Backend;
23 } 23 }
24 24
25 protected: 25 protected:
26 const char* onGetName() override { 26 const char* onGetName() override {
27 return "atomic_inc_32"; 27 return "atomic_inc_32";
28 } 28 }
29 29
30 void onDraw(const int loops, SkCanvas*) override { 30 void onDraw(int loops, SkCanvas*) override {
31 for (int i = 0; i < loops; ++i) { 31 for (int i = 0; i < loops; ++i) {
32 sk_atomic_inc(&fX); 32 sk_atomic_inc(&fX);
33 } 33 }
34 } 34 }
35 35
36 private: 36 private:
37 int32_t fX; 37 int32_t fX;
38 typedef Benchmark INHERITED; 38 typedef Benchmark INHERITED;
39 }; 39 };
40 40
41 class AtomicInc64 : public Benchmark { 41 class AtomicInc64 : public Benchmark {
42 public: 42 public:
43 AtomicInc64() : fX(0) {} 43 AtomicInc64() : fX(0) {}
44 44
45 bool isSuitableFor(Backend backend) override { 45 bool isSuitableFor(Backend backend) override {
46 return backend == kNonRendering_Backend; 46 return backend == kNonRendering_Backend;
47 } 47 }
48 48
49 protected: 49 protected:
50 const char* onGetName() override { 50 const char* onGetName() override {
51 return "atomic_inc_64"; 51 return "atomic_inc_64";
52 } 52 }
53 53
54 void onDraw(const int loops, SkCanvas*) override { 54 void onDraw(int loops, SkCanvas*) override {
55 for (int i = 0; i < loops; ++i) { 55 for (int i = 0; i < loops; ++i) {
56 sk_atomic_inc(&fX); 56 sk_atomic_inc(&fX);
57 } 57 }
58 } 58 }
59 59
60 private: 60 private:
61 int64_t fX; 61 int64_t fX;
62 typedef Benchmark INHERITED; 62 typedef Benchmark INHERITED;
63 }; 63 };
64 64
65 class RefCntBench_Stack : public Benchmark { 65 class RefCntBench_Stack : public Benchmark {
66 public: 66 public:
67 bool isSuitableFor(Backend backend) override { 67 bool isSuitableFor(Backend backend) override {
68 return backend == kNonRendering_Backend; 68 return backend == kNonRendering_Backend;
69 } 69 }
70 70
71 protected: 71 protected:
72 const char* onGetName() override { 72 const char* onGetName() override {
73 return "ref_cnt_stack"; 73 return "ref_cnt_stack";
74 } 74 }
75 75
76 void onDraw(const int loops, SkCanvas*) override { 76 void onDraw(int loops, SkCanvas*) override {
77 for (int i = 0; i < loops; ++i) { 77 for (int i = 0; i < loops; ++i) {
78 SkRefCnt ref; 78 SkRefCnt ref;
79 for (int j = 0; j < M; ++j) { 79 for (int j = 0; j < M; ++j) {
80 ref.ref(); 80 ref.ref();
81 ref.unref(); 81 ref.unref();
82 } 82 }
83 } 83 }
84 } 84 }
85 85
86 private: 86 private:
(...skipping 13 matching lines...) Expand all
100 public: 100 public:
101 bool isSuitableFor(Backend backend) override { 101 bool isSuitableFor(Backend backend) override {
102 return backend == kNonRendering_Backend; 102 return backend == kNonRendering_Backend;
103 } 103 }
104 104
105 protected: 105 protected:
106 const char* onGetName() override { 106 const char* onGetName() override {
107 return "ref_cnt_heap"; 107 return "ref_cnt_heap";
108 } 108 }
109 109
110 void onDraw(const int loops, SkCanvas*) override { 110 void onDraw(int loops, SkCanvas*) override {
111 char memory[sizeof(PlacedRefCnt)]; 111 char memory[sizeof(PlacedRefCnt)];
112 for (int i = 0; i < loops; ++i) { 112 for (int i = 0; i < loops; ++i) {
113 PlacedRefCnt* ref = new (memory) PlacedRefCnt(); 113 PlacedRefCnt* ref = new (memory) PlacedRefCnt();
114 for (int j = 0; j < M; ++j) { 114 for (int j = 0; j < M; ++j) {
115 ref->ref(); 115 ref->ref();
116 ref->unref(); 116 ref->unref();
117 } 117 }
118 ref->unref(); 118 ref->unref();
119 } 119 }
120 } 120 }
121 121
122 private: 122 private:
123 typedef Benchmark INHERITED; 123 typedef Benchmark INHERITED;
124 }; 124 };
125 125
126 class RefCntBench_New : public Benchmark { 126 class RefCntBench_New : public Benchmark {
127 public: 127 public:
128 bool isSuitableFor(Backend backend) override { 128 bool isSuitableFor(Backend backend) override {
129 return backend == kNonRendering_Backend; 129 return backend == kNonRendering_Backend;
130 } 130 }
131 131
132 protected: 132 protected:
133 const char* onGetName() override { 133 const char* onGetName() override {
134 return "ref_cnt_new"; 134 return "ref_cnt_new";
135 } 135 }
136 136
137 void onDraw(const int loops, SkCanvas*) override { 137 void onDraw(int loops, SkCanvas*) override {
138 for (int i = 0; i < loops; ++i) { 138 for (int i = 0; i < loops; ++i) {
139 SkRefCnt* ref = new SkRefCnt(); 139 SkRefCnt* ref = new SkRefCnt();
140 for (int j = 0; j < M; ++j) { 140 for (int j = 0; j < M; ++j) {
141 ref->ref(); 141 ref->ref();
142 ref->unref(); 142 ref->unref();
143 } 143 }
144 ref->unref(); 144 ref->unref();
145 } 145 }
146 } 146 }
147 147
148 private: 148 private:
149 typedef Benchmark INHERITED; 149 typedef Benchmark INHERITED;
150 }; 150 };
151 151
152 /////////////////////////////////////////////////////////////////////////////// 152 ///////////////////////////////////////////////////////////////////////////////
153 153
154 class WeakRefCntBench_Stack : public Benchmark { 154 class WeakRefCntBench_Stack : public Benchmark {
155 public: 155 public:
156 bool isSuitableFor(Backend backend) override { 156 bool isSuitableFor(Backend backend) override {
157 return backend == kNonRendering_Backend; 157 return backend == kNonRendering_Backend;
158 } 158 }
159 159
160 protected: 160 protected:
161 const char* onGetName() override { 161 const char* onGetName() override {
162 return "ref_cnt_stack_weak"; 162 return "ref_cnt_stack_weak";
163 } 163 }
164 164
165 void onDraw(const int loops, SkCanvas*) override { 165 void onDraw(int loops, SkCanvas*) override {
166 for (int i = 0; i < loops; ++i) { 166 for (int i = 0; i < loops; ++i) {
167 SkWeakRefCnt ref; 167 SkWeakRefCnt ref;
168 for (int j = 0; j < M; ++j) { 168 for (int j = 0; j < M; ++j) {
169 ref.ref(); 169 ref.ref();
170 ref.unref(); 170 ref.unref();
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 private: 175 private:
(...skipping 10 matching lines...) Expand all
186 public: 186 public:
187 bool isSuitableFor(Backend backend) override { 187 bool isSuitableFor(Backend backend) override {
188 return backend == kNonRendering_Backend; 188 return backend == kNonRendering_Backend;
189 } 189 }
190 190
191 protected: 191 protected:
192 const char* onGetName() override { 192 const char* onGetName() override {
193 return "ref_cnt_heap_weak"; 193 return "ref_cnt_heap_weak";
194 } 194 }
195 195
196 void onDraw(const int loops, SkCanvas*) override { 196 void onDraw(int loops, SkCanvas*) override {
197 char memory[sizeof(PlacedWeakRefCnt)]; 197 char memory[sizeof(PlacedWeakRefCnt)];
198 for (int i = 0; i < loops; ++i) { 198 for (int i = 0; i < loops; ++i) {
199 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt(); 199 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
200 for (int j = 0; j < M; ++j) { 200 for (int j = 0; j < M; ++j) {
201 ref->ref(); 201 ref->ref();
202 ref->unref(); 202 ref->unref();
203 } 203 }
204 ref->unref(); 204 ref->unref();
205 } 205 }
206 } 206 }
207 207
208 private: 208 private:
209 typedef Benchmark INHERITED; 209 typedef Benchmark INHERITED;
210 }; 210 };
211 211
212 class WeakRefCntBench_New : public Benchmark { 212 class WeakRefCntBench_New : public Benchmark {
213 public: 213 public:
214 bool isSuitableFor(Backend backend) override { 214 bool isSuitableFor(Backend backend) override {
215 return backend == kNonRendering_Backend; 215 return backend == kNonRendering_Backend;
216 } 216 }
217 217
218 protected: 218 protected:
219 const char* onGetName() override { 219 const char* onGetName() override {
220 return "ref_cnt_new_weak"; 220 return "ref_cnt_new_weak";
221 } 221 }
222 222
223 void onDraw(const int loops, SkCanvas*) override { 223 void onDraw(int loops, SkCanvas*) override {
224 for (int i = 0; i < loops; ++i) { 224 for (int i = 0; i < loops; ++i) {
225 SkWeakRefCnt* ref = new SkWeakRefCnt(); 225 SkWeakRefCnt* ref = new SkWeakRefCnt();
226 for (int j = 0; j < M; ++j) { 226 for (int j = 0; j < M; ++j) {
227 ref->ref(); 227 ref->ref();
228 ref->unref(); 228 ref->unref();
229 } 229 }
230 ref->unref(); 230 ref->unref();
231 } 231 }
232 } 232 }
233 233
234 private: 234 private:
235 typedef Benchmark INHERITED; 235 typedef Benchmark INHERITED;
236 }; 236 };
237 237
238 /////////////////////////////////////////////////////////////////////////////// 238 ///////////////////////////////////////////////////////////////////////////////
239 239
240 DEF_BENCH( return new AtomicInc32(); ) 240 DEF_BENCH( return new AtomicInc32(); )
241 DEF_BENCH( return new AtomicInc64(); ) 241 DEF_BENCH( return new AtomicInc64(); )
242 242
243 DEF_BENCH( return new RefCntBench_Stack(); ) 243 DEF_BENCH( return new RefCntBench_Stack(); )
244 DEF_BENCH( return new RefCntBench_Heap(); ) 244 DEF_BENCH( return new RefCntBench_Heap(); )
245 DEF_BENCH( return new RefCntBench_New(); ) 245 DEF_BENCH( return new RefCntBench_New(); )
246 246
247 DEF_BENCH( return new WeakRefCntBench_Stack(); ) 247 DEF_BENCH( return new WeakRefCntBench_Stack(); )
248 DEF_BENCH( return new WeakRefCntBench_Heap(); ) 248 DEF_BENCH( return new WeakRefCntBench_Heap(); )
249 DEF_BENCH( return new WeakRefCntBench_New(); ) 249 DEF_BENCH( return new WeakRefCntBench_New(); )
OLDNEW
« no previous file with comments | « bench/RectoriBench.cpp ('k') | bench/RegionBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698