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