2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkWeakRefCnt.h"
17 class AtomicInc32 : public Benchmark {
19 AtomicInc32() : fX(0) {}
21 bool isSuitableFor(Backend backend) override {
22 return backend == kNonRendering_Backend;
26 virtual const char* onGetName() {
27 return "atomic_inc_32";
30 virtual void onDraw(const int loops, SkCanvas*) {
31 for (int i = 0; i < loops; ++i) {
38 typedef Benchmark INHERITED;
41 class AtomicInc64 : public Benchmark {
43 AtomicInc64() : fX(0) {}
45 bool isSuitableFor(Backend backend) override {
46 return backend == kNonRendering_Backend;
50 virtual const char* onGetName() {
51 return "atomic_inc_64";
54 virtual void onDraw(const int loops, SkCanvas*) {
55 for (int i = 0; i < loops; ++i) {
62 typedef Benchmark INHERITED;
65 class RefCntBench_Stack : public Benchmark {
67 bool isSuitableFor(Backend backend) override {
68 return backend == kNonRendering_Backend;
72 virtual const char* onGetName() {
73 return "ref_cnt_stack";
76 virtual void onDraw(const int loops, SkCanvas*) {
77 for (int i = 0; i < loops; ++i) {
79 for (int j = 0; j < M; ++j) {
87 typedef Benchmark INHERITED;
90 class PlacedRefCnt : public SkRefCnt {
92 SK_DECLARE_INST_COUNT(PlacedRefCnt)
94 PlacedRefCnt() : SkRefCnt() { }
95 void operator delete(void*) { }
98 typedef SkRefCnt INHERITED;
101 class RefCntBench_Heap : public Benchmark {
103 bool isSuitableFor(Backend backend) override {
104 return backend == kNonRendering_Backend;
108 virtual const char* onGetName() {
109 return "ref_cnt_heap";
112 virtual void onDraw(const int loops, SkCanvas*) {
113 char memory[sizeof(PlacedRefCnt)];
114 for (int i = 0; i < loops; ++i) {
115 PlacedRefCnt* ref = new (memory) PlacedRefCnt();
116 for (int j = 0; j < M; ++j) {
125 typedef Benchmark INHERITED;
128 class RefCntBench_New : public Benchmark {
130 bool isSuitableFor(Backend backend) override {
131 return backend == kNonRendering_Backend;
135 virtual const char* onGetName() {
136 return "ref_cnt_new";
139 virtual void onDraw(const int loops, SkCanvas*) {
140 for (int i = 0; i < loops; ++i) {
141 SkRefCnt* ref = new SkRefCnt();
142 for (int j = 0; j < M; ++j) {
151 typedef Benchmark INHERITED;
154 ///////////////////////////////////////////////////////////////////////////////
156 class WeakRefCntBench_Stack : public Benchmark {
158 bool isSuitableFor(Backend backend) override {
159 return backend == kNonRendering_Backend;
163 virtual const char* onGetName() {
164 return "ref_cnt_stack_weak";
167 virtual void onDraw(const int loops, SkCanvas*) {
168 for (int i = 0; i < loops; ++i) {
170 for (int j = 0; j < M; ++j) {
178 typedef Benchmark INHERITED;
181 class PlacedWeakRefCnt : public SkWeakRefCnt {
183 PlacedWeakRefCnt() : SkWeakRefCnt() { }
184 void operator delete(void*) { }
187 class WeakRefCntBench_Heap : public Benchmark {
189 bool isSuitableFor(Backend backend) override {
190 return backend == kNonRendering_Backend;
194 const char* onGetName() override {
195 return "ref_cnt_heap_weak";
198 void onDraw(const int loops, SkCanvas*) override {
199 char memory[sizeof(PlacedWeakRefCnt)];
200 for (int i = 0; i < loops; ++i) {
201 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
202 for (int j = 0; j < M; ++j) {
211 typedef Benchmark INHERITED;
214 class WeakRefCntBench_New : public Benchmark {
216 bool isSuitableFor(Backend backend) override {
217 return backend == kNonRendering_Backend;
221 const char* onGetName() override {
222 return "ref_cnt_new_weak";
225 void onDraw(const int loops, SkCanvas*) override {
226 for (int i = 0; i < loops; ++i) {
227 SkWeakRefCnt* ref = new SkWeakRefCnt();
228 for (int j = 0; j < M; ++j) {
237 typedef Benchmark INHERITED;
240 ///////////////////////////////////////////////////////////////////////////////
242 DEF_BENCH( return new AtomicInc32(); )
243 DEF_BENCH( return new AtomicInc64(); )
245 DEF_BENCH( return new RefCntBench_Stack(); )
246 DEF_BENCH( return new RefCntBench_Heap(); )
247 DEF_BENCH( return new RefCntBench_New(); )
249 DEF_BENCH( return new WeakRefCntBench_Stack(); )
250 DEF_BENCH( return new WeakRefCntBench_Heap(); )
251 DEF_BENCH( return new WeakRefCntBench_New(); )