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