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