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

Side by Side Diff: bench/RefCntBench.cpp

Issue 99893003: Simplify benchmark internal API. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
« 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 "SkBenchmark.h" 7 #include "SkBenchmark.h"
8 #include "SkRefCnt.h" 8 #include "SkRefCnt.h"
9 #include "SkThread.h" 9 #include "SkThread.h"
10 #include "SkWeakRefCnt.h" 10 #include "SkWeakRefCnt.h"
11 #include <memory> 11 #include <memory>
12 12
13 enum { 13 enum {
14 M = 2 14 M = 2
15 }; 15 };
16 16
17 class RefCntBench_Stack : public SkBenchmark { 17 class RefCntBench_Stack : public SkBenchmark {
18 public: 18 public:
19 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 19 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
20 return backend == kNonRendering_Backend; 20 return backend == kNonRendering_Backend;
21 } 21 }
22 22
23 protected: 23 protected:
24 virtual const char* onGetName() { 24 virtual const char* onGetName() {
25 return "ref_cnt_stack"; 25 return "ref_cnt_stack";
26 } 26 }
27 27
28 virtual void onDraw(SkCanvas*) { 28 virtual void onDraw(const int loops, SkCanvas*) {
29 for (int i = 0; i < this->getLoops(); ++i) { 29 for (int i = 0; i < loops; ++i) {
30 SkRefCnt ref; 30 SkRefCnt ref;
31 for (int j = 0; j < M; ++j) { 31 for (int j = 0; j < M; ++j) {
32 ref.ref(); 32 ref.ref();
33 ref.unref(); 33 ref.unref();
34 } 34 }
35 } 35 }
36 } 36 }
37 37
38 private: 38 private:
39 typedef SkBenchmark INHERITED; 39 typedef SkBenchmark INHERITED;
(...skipping 16 matching lines...) Expand all
56 public: 56 public:
57 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 57 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
58 return backend == kNonRendering_Backend; 58 return backend == kNonRendering_Backend;
59 } 59 }
60 60
61 protected: 61 protected:
62 virtual const char* onGetName() { 62 virtual const char* onGetName() {
63 return "ref_cnt_heap"; 63 return "ref_cnt_heap";
64 } 64 }
65 65
66 virtual void onDraw(SkCanvas*) { 66 virtual void onDraw(const int loops, SkCanvas*) {
67 char memory[sizeof(PlacedRefCnt)]; 67 char memory[sizeof(PlacedRefCnt)];
68 for (int i = 0; i < this->getLoops(); ++i) { 68 for (int i = 0; i < loops; ++i) {
69 PlacedRefCnt* ref = new (memory) PlacedRefCnt(); 69 PlacedRefCnt* ref = new (memory) PlacedRefCnt();
70 for (int j = 0; j < M; ++j) { 70 for (int j = 0; j < M; ++j) {
71 ref->ref(); 71 ref->ref();
72 ref->unref(); 72 ref->unref();
73 } 73 }
74 ref->unref(); 74 ref->unref();
75 } 75 }
76 } 76 }
77 77
78 private: 78 private:
79 typedef SkBenchmark INHERITED; 79 typedef SkBenchmark INHERITED;
80 }; 80 };
81 81
82 class RefCntBench_New : public SkBenchmark { 82 class RefCntBench_New : public SkBenchmark {
83 public: 83 public:
84 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 84 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
85 return backend == kNonRendering_Backend; 85 return backend == kNonRendering_Backend;
86 } 86 }
87 87
88 protected: 88 protected:
89 virtual const char* onGetName() { 89 virtual const char* onGetName() {
90 return "ref_cnt_new"; 90 return "ref_cnt_new";
91 } 91 }
92 92
93 virtual void onDraw(SkCanvas*) { 93 virtual void onDraw(const int loops, SkCanvas*) {
94 for (int i = 0; i < this->getLoops(); ++i) { 94 for (int i = 0; i < loops; ++i) {
95 SkRefCnt* ref = new SkRefCnt(); 95 SkRefCnt* ref = new SkRefCnt();
96 for (int j = 0; j < M; ++j) { 96 for (int j = 0; j < M; ++j) {
97 ref->ref(); 97 ref->ref();
98 ref->unref(); 98 ref->unref();
99 } 99 }
100 ref->unref(); 100 ref->unref();
101 } 101 }
102 } 102 }
103 103
104 private: 104 private:
105 typedef SkBenchmark INHERITED; 105 typedef SkBenchmark INHERITED;
106 }; 106 };
107 107
108 /////////////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////////////
109 109
110 class WeakRefCntBench_Stack : public SkBenchmark { 110 class WeakRefCntBench_Stack : public SkBenchmark {
111 public: 111 public:
112 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 112 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
113 return backend == kNonRendering_Backend; 113 return backend == kNonRendering_Backend;
114 } 114 }
115 115
116 protected: 116 protected:
117 virtual const char* onGetName() { 117 virtual const char* onGetName() {
118 return "ref_cnt_stack_weak"; 118 return "ref_cnt_stack_weak";
119 } 119 }
120 120
121 virtual void onDraw(SkCanvas*) { 121 virtual void onDraw(const int loops, SkCanvas*) {
122 for (int i = 0; i < this->getLoops(); ++i) { 122 for (int i = 0; i < loops; ++i) {
123 SkWeakRefCnt ref; 123 SkWeakRefCnt ref;
124 for (int j = 0; j < M; ++j) { 124 for (int j = 0; j < M; ++j) {
125 ref.ref(); 125 ref.ref();
126 ref.unref(); 126 ref.unref();
127 } 127 }
128 } 128 }
129 } 129 }
130 130
131 private: 131 private:
132 typedef SkBenchmark INHERITED; 132 typedef SkBenchmark INHERITED;
133 }; 133 };
134 134
135 class PlacedWeakRefCnt : public SkWeakRefCnt { 135 class PlacedWeakRefCnt : public SkWeakRefCnt {
136 public: 136 public:
137 PlacedWeakRefCnt() : SkWeakRefCnt() { } 137 PlacedWeakRefCnt() : SkWeakRefCnt() { }
138 void operator delete(void*) { } 138 void operator delete(void*) { }
139 }; 139 };
140 140
141 class WeakRefCntBench_Heap : public SkBenchmark { 141 class WeakRefCntBench_Heap : public SkBenchmark {
142 public: 142 public:
143 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 143 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
144 return backend == kNonRendering_Backend; 144 return backend == kNonRendering_Backend;
145 } 145 }
146 146
147 protected: 147 protected:
148 virtual const char* onGetName() { 148 virtual const char* onGetName() {
149 return "ref_cnt_heap_weak"; 149 return "ref_cnt_heap_weak";
150 } 150 }
151 151
152 virtual void onDraw(SkCanvas*) { 152 virtual void onDraw(const int loops, SkCanvas*) {
153 char memory[sizeof(PlacedWeakRefCnt)]; 153 char memory[sizeof(PlacedWeakRefCnt)];
154 for (int i = 0; i < this->getLoops(); ++i) { 154 for (int i = 0; i < loops; ++i) {
155 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt(); 155 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
156 for (int j = 0; j < M; ++j) { 156 for (int j = 0; j < M; ++j) {
157 ref->ref(); 157 ref->ref();
158 ref->unref(); 158 ref->unref();
159 } 159 }
160 ref->unref(); 160 ref->unref();
161 } 161 }
162 } 162 }
163 163
164 private: 164 private:
165 typedef SkBenchmark INHERITED; 165 typedef SkBenchmark INHERITED;
166 }; 166 };
167 167
168 class WeakRefCntBench_New : public SkBenchmark { 168 class WeakRefCntBench_New : public SkBenchmark {
169 public: 169 public:
170 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 170 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
171 return backend == kNonRendering_Backend; 171 return backend == kNonRendering_Backend;
172 } 172 }
173 173
174 protected: 174 protected:
175 virtual const char* onGetName() { 175 virtual const char* onGetName() {
176 return "ref_cnt_new_weak"; 176 return "ref_cnt_new_weak";
177 } 177 }
178 178
179 virtual void onDraw(SkCanvas*) { 179 virtual void onDraw(const int loops, SkCanvas*) {
180 for (int i = 0; i < this->getLoops(); ++i) { 180 for (int i = 0; i < loops; ++i) {
181 SkWeakRefCnt* ref = new SkWeakRefCnt(); 181 SkWeakRefCnt* ref = new SkWeakRefCnt();
182 for (int j = 0; j < M; ++j) { 182 for (int j = 0; j < M; ++j) {
183 ref->ref(); 183 ref->ref();
184 ref->unref(); 184 ref->unref();
185 } 185 }
186 ref->unref(); 186 ref->unref();
187 } 187 }
188 } 188 }
189 189
190 private: 190 private:
191 typedef SkBenchmark INHERITED; 191 typedef SkBenchmark INHERITED;
192 }; 192 };
193 193
194 /////////////////////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////////////////////
195 195
196 DEF_BENCH( return new RefCntBench_Stack(); ) 196 DEF_BENCH( return new RefCntBench_Stack(); )
197 DEF_BENCH( return new RefCntBench_Heap(); ) 197 DEF_BENCH( return new RefCntBench_Heap(); )
198 DEF_BENCH( return new RefCntBench_New(); ) 198 DEF_BENCH( return new RefCntBench_New(); )
199 199
200 DEF_BENCH( return new WeakRefCntBench_Stack(); ) 200 DEF_BENCH( return new WeakRefCntBench_Stack(); )
201 DEF_BENCH( return new WeakRefCntBench_Heap(); ) 201 DEF_BENCH( return new WeakRefCntBench_Heap(); )
202 DEF_BENCH( return new WeakRefCntBench_New(); ) 202 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