OLD | NEW |
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 RefCntBench_Stack(void* param) : INHERITED(param) { | 19 RefCntBench_Stack() { |
20 fIsRendering = false; | 20 fIsRendering = false; |
21 } | 21 } |
22 protected: | 22 protected: |
23 virtual const char* onGetName() { | 23 virtual const char* onGetName() { |
24 return "ref_cnt_stack"; | 24 return "ref_cnt_stack"; |
25 } | 25 } |
26 | 26 |
27 virtual void onDraw(SkCanvas*) { | 27 virtual void onDraw(SkCanvas*) { |
28 for (int i = 0; i < this->getLoops(); ++i) { | 28 for (int i = 0; i < this->getLoops(); ++i) { |
29 SkRefCnt ref; | 29 SkRefCnt ref; |
(...skipping 16 matching lines...) Expand all Loading... |
46 void operator delete(void*) { } | 46 void operator delete(void*) { } |
47 | 47 |
48 private: | 48 private: |
49 typedef SkRefCnt INHERITED; | 49 typedef SkRefCnt INHERITED; |
50 }; | 50 }; |
51 | 51 |
52 SK_DEFINE_INST_COUNT(PlacedRefCnt) | 52 SK_DEFINE_INST_COUNT(PlacedRefCnt) |
53 | 53 |
54 class RefCntBench_Heap : public SkBenchmark { | 54 class RefCntBench_Heap : public SkBenchmark { |
55 public: | 55 public: |
56 RefCntBench_Heap(void* param) : INHERITED(param) { | 56 RefCntBench_Heap() { |
57 fIsRendering = false; | 57 fIsRendering = false; |
58 } | 58 } |
59 protected: | 59 protected: |
60 virtual const char* onGetName() { | 60 virtual const char* onGetName() { |
61 return "ref_cnt_heap"; | 61 return "ref_cnt_heap"; |
62 } | 62 } |
63 | 63 |
64 virtual void onDraw(SkCanvas*) { | 64 virtual void onDraw(SkCanvas*) { |
65 char memory[sizeof(PlacedRefCnt)]; | 65 char memory[sizeof(PlacedRefCnt)]; |
66 for (int i = 0; i < this->getLoops(); ++i) { | 66 for (int i = 0; i < this->getLoops(); ++i) { |
67 PlacedRefCnt* ref = new (memory) PlacedRefCnt(); | 67 PlacedRefCnt* ref = new (memory) PlacedRefCnt(); |
68 for (int j = 0; j < M; ++j) { | 68 for (int j = 0; j < M; ++j) { |
69 ref->ref(); | 69 ref->ref(); |
70 ref->unref(); | 70 ref->unref(); |
71 } | 71 } |
72 ref->unref(); | 72 ref->unref(); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 private: | 76 private: |
77 typedef SkBenchmark INHERITED; | 77 typedef SkBenchmark INHERITED; |
78 }; | 78 }; |
79 | 79 |
80 class RefCntBench_New : public SkBenchmark { | 80 class RefCntBench_New : public SkBenchmark { |
81 public: | 81 public: |
82 RefCntBench_New(void* param) : INHERITED(param) { | 82 RefCntBench_New() { |
83 fIsRendering = false; | 83 fIsRendering = false; |
84 } | 84 } |
85 protected: | 85 protected: |
86 virtual const char* onGetName() { | 86 virtual const char* onGetName() { |
87 return "ref_cnt_new"; | 87 return "ref_cnt_new"; |
88 } | 88 } |
89 | 89 |
90 virtual void onDraw(SkCanvas*) { | 90 virtual void onDraw(SkCanvas*) { |
91 for (int i = 0; i < this->getLoops(); ++i) { | 91 for (int i = 0; i < this->getLoops(); ++i) { |
92 SkRefCnt* ref = new SkRefCnt(); | 92 SkRefCnt* ref = new SkRefCnt(); |
93 for (int j = 0; j < M; ++j) { | 93 for (int j = 0; j < M; ++j) { |
94 ref->ref(); | 94 ref->ref(); |
95 ref->unref(); | 95 ref->unref(); |
96 } | 96 } |
97 ref->unref(); | 97 ref->unref(); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 private: | 101 private: |
102 typedef SkBenchmark INHERITED; | 102 typedef SkBenchmark INHERITED; |
103 }; | 103 }; |
104 | 104 |
105 /////////////////////////////////////////////////////////////////////////////// | 105 /////////////////////////////////////////////////////////////////////////////// |
106 | 106 |
107 class WeakRefCntBench_Stack : public SkBenchmark { | 107 class WeakRefCntBench_Stack : public SkBenchmark { |
108 public: | 108 public: |
109 WeakRefCntBench_Stack(void* param) : INHERITED(param) { | 109 WeakRefCntBench_Stack() { |
110 fIsRendering = false; | 110 fIsRendering = false; |
111 } | 111 } |
112 protected: | 112 protected: |
113 virtual const char* onGetName() { | 113 virtual const char* onGetName() { |
114 return "ref_cnt_stack_weak"; | 114 return "ref_cnt_stack_weak"; |
115 } | 115 } |
116 | 116 |
117 virtual void onDraw(SkCanvas*) { | 117 virtual void onDraw(SkCanvas*) { |
118 for (int i = 0; i < this->getLoops(); ++i) { | 118 for (int i = 0; i < this->getLoops(); ++i) { |
119 SkWeakRefCnt ref; | 119 SkWeakRefCnt ref; |
120 for (int j = 0; j < M; ++j) { | 120 for (int j = 0; j < M; ++j) { |
121 ref.ref(); | 121 ref.ref(); |
122 ref.unref(); | 122 ref.unref(); |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 private: | 127 private: |
128 typedef SkBenchmark INHERITED; | 128 typedef SkBenchmark INHERITED; |
129 }; | 129 }; |
130 | 130 |
131 class PlacedWeakRefCnt : public SkWeakRefCnt { | 131 class PlacedWeakRefCnt : public SkWeakRefCnt { |
132 public: | 132 public: |
133 PlacedWeakRefCnt() : SkWeakRefCnt() { } | 133 PlacedWeakRefCnt() : SkWeakRefCnt() { } |
134 void operator delete(void*) { } | 134 void operator delete(void*) { } |
135 }; | 135 }; |
136 | 136 |
137 class WeakRefCntBench_Heap : public SkBenchmark { | 137 class WeakRefCntBench_Heap : public SkBenchmark { |
138 public: | 138 public: |
139 WeakRefCntBench_Heap(void* param) : INHERITED(param) { | 139 WeakRefCntBench_Heap() { |
140 fIsRendering = false; | 140 fIsRendering = false; |
141 } | 141 } |
142 protected: | 142 protected: |
143 virtual const char* onGetName() { | 143 virtual const char* onGetName() { |
144 return "ref_cnt_heap_weak"; | 144 return "ref_cnt_heap_weak"; |
145 } | 145 } |
146 | 146 |
147 virtual void onDraw(SkCanvas*) { | 147 virtual void onDraw(SkCanvas*) { |
148 char memory[sizeof(PlacedWeakRefCnt)]; | 148 char memory[sizeof(PlacedWeakRefCnt)]; |
149 for (int i = 0; i < this->getLoops(); ++i) { | 149 for (int i = 0; i < this->getLoops(); ++i) { |
150 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt(); | 150 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt(); |
151 for (int j = 0; j < M; ++j) { | 151 for (int j = 0; j < M; ++j) { |
152 ref->ref(); | 152 ref->ref(); |
153 ref->unref(); | 153 ref->unref(); |
154 } | 154 } |
155 ref->unref(); | 155 ref->unref(); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 private: | 159 private: |
160 typedef SkBenchmark INHERITED; | 160 typedef SkBenchmark INHERITED; |
161 }; | 161 }; |
162 | 162 |
163 class WeakRefCntBench_New : public SkBenchmark { | 163 class WeakRefCntBench_New : public SkBenchmark { |
164 public: | 164 public: |
165 WeakRefCntBench_New(void* param) : INHERITED(param) { | 165 WeakRefCntBench_New() { |
166 fIsRendering = false; | 166 fIsRendering = false; |
167 } | 167 } |
168 protected: | 168 protected: |
169 virtual const char* onGetName() { | 169 virtual const char* onGetName() { |
170 return "ref_cnt_new_weak"; | 170 return "ref_cnt_new_weak"; |
171 } | 171 } |
172 | 172 |
173 virtual void onDraw(SkCanvas*) { | 173 virtual void onDraw(SkCanvas*) { |
174 for (int i = 0; i < this->getLoops(); ++i) { | 174 for (int i = 0; i < this->getLoops(); ++i) { |
175 SkWeakRefCnt* ref = new SkWeakRefCnt(); | 175 SkWeakRefCnt* ref = new SkWeakRefCnt(); |
176 for (int j = 0; j < M; ++j) { | 176 for (int j = 0; j < M; ++j) { |
177 ref->ref(); | 177 ref->ref(); |
178 ref->unref(); | 178 ref->unref(); |
179 } | 179 } |
180 ref->unref(); | 180 ref->unref(); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 private: | 184 private: |
185 typedef SkBenchmark INHERITED; | 185 typedef SkBenchmark INHERITED; |
186 }; | 186 }; |
187 | 187 |
188 /////////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////////// |
189 | 189 |
190 static SkBenchmark* Fact00(void* p) { return new RefCntBench_Stack(p); } | 190 DEF_BENCH( return new RefCntBench_Stack(); ) |
191 static SkBenchmark* Fact01(void* p) { return new RefCntBench_Heap(p); } | 191 DEF_BENCH( return new RefCntBench_Heap(); ) |
192 static SkBenchmark* Fact02(void* p) { return new RefCntBench_New(p); } | 192 DEF_BENCH( return new RefCntBench_New(); ) |
193 | 193 |
194 static SkBenchmark* Fact10(void* p) { return new WeakRefCntBench_Stack(p); } | 194 DEF_BENCH( return new WeakRefCntBench_Stack(); ) |
195 static SkBenchmark* Fact11(void* p) { return new WeakRefCntBench_Heap(p); } | 195 DEF_BENCH( return new WeakRefCntBench_Heap(); ) |
196 static SkBenchmark* Fact12(void* p) { return new WeakRefCntBench_New(p); } | 196 DEF_BENCH( return new WeakRefCntBench_New(); ) |
197 | |
198 static BenchRegistry gReg00(Fact00); | |
199 static BenchRegistry gReg01(Fact01); | |
200 static BenchRegistry gReg02(Fact02); | |
201 | |
202 static BenchRegistry gReg10(Fact10); | |
203 static BenchRegistry gReg11(Fact11); | |
204 static BenchRegistry gReg12(Fact12); | |
OLD | NEW |