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 <memory> | 7 #include <memory> |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkRefCnt.h" | 9 #include "SkRefCnt.h" |
10 #include "SkThread.h" | 10 #include "SkThread.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 { |
| 18 public: |
| 19 AtomicInc32() : fX(0) {} |
| 20 |
| 21 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 22 return backend == kNonRendering_Backend; |
| 23 } |
| 24 |
| 25 protected: |
| 26 virtual const char* onGetName() { |
| 27 return "atomic_inc_32"; |
| 28 } |
| 29 |
| 30 virtual void onDraw(const int loops, SkCanvas*) { |
| 31 for (int i = 0; i < loops; ++i) { |
| 32 sk_atomic_inc(&fX); |
| 33 } |
| 34 } |
| 35 |
| 36 private: |
| 37 int32_t fX; |
| 38 typedef Benchmark INHERITED; |
| 39 }; |
| 40 |
| 41 class AtomicInc64 : public Benchmark { |
| 42 public: |
| 43 AtomicInc64() : fX(0) {} |
| 44 |
| 45 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 46 return backend == kNonRendering_Backend; |
| 47 } |
| 48 |
| 49 protected: |
| 50 virtual const char* onGetName() { |
| 51 return "atomic_inc_64"; |
| 52 } |
| 53 |
| 54 virtual void onDraw(const int loops, SkCanvas*) { |
| 55 for (int i = 0; i < loops; ++i) { |
| 56 sk_atomic_inc(&fX); |
| 57 } |
| 58 } |
| 59 |
| 60 private: |
| 61 int64_t fX; |
| 62 typedef Benchmark INHERITED; |
| 63 }; |
| 64 |
17 class RefCntBench_Stack : public Benchmark { | 65 class RefCntBench_Stack : public Benchmark { |
18 public: | 66 public: |
19 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 67 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
20 return backend == kNonRendering_Backend; | 68 return backend == kNonRendering_Backend; |
21 } | 69 } |
22 | 70 |
23 protected: | 71 protected: |
24 virtual const char* onGetName() { | 72 virtual const char* onGetName() { |
25 return "ref_cnt_stack"; | 73 return "ref_cnt_stack"; |
26 } | 74 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 ref->unref(); | 232 ref->unref(); |
185 } | 233 } |
186 } | 234 } |
187 | 235 |
188 private: | 236 private: |
189 typedef Benchmark INHERITED; | 237 typedef Benchmark INHERITED; |
190 }; | 238 }; |
191 | 239 |
192 /////////////////////////////////////////////////////////////////////////////// | 240 /////////////////////////////////////////////////////////////////////////////// |
193 | 241 |
| 242 DEF_BENCH( return new AtomicInc32(); ) |
| 243 DEF_BENCH( return new AtomicInc64(); ) |
| 244 |
194 DEF_BENCH( return new RefCntBench_Stack(); ) | 245 DEF_BENCH( return new RefCntBench_Stack(); ) |
195 DEF_BENCH( return new RefCntBench_Heap(); ) | 246 DEF_BENCH( return new RefCntBench_Heap(); ) |
196 DEF_BENCH( return new RefCntBench_New(); ) | 247 DEF_BENCH( return new RefCntBench_New(); ) |
197 | 248 |
198 DEF_BENCH( return new WeakRefCntBench_Stack(); ) | 249 DEF_BENCH( return new WeakRefCntBench_Stack(); ) |
199 DEF_BENCH( return new WeakRefCntBench_Heap(); ) | 250 DEF_BENCH( return new WeakRefCntBench_Heap(); ) |
200 DEF_BENCH( return new WeakRefCntBench_New(); ) | 251 DEF_BENCH( return new WeakRefCntBench_New(); ) |
OLD | NEW |