Flutter Engine
The Flutter Engine
RefCntBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "bench/Benchmark.h"
10#include <memory>
11#include <new>
12
13enum {
14 M = 2
15};
16
18public:
19 bool isSuitableFor(Backend backend) override {
21 }
22
23protected:
24 const char* onGetName() override {
25 return "ref_cnt_stack";
26 }
27
28 void onDraw(int loops, SkCanvas*) override {
29 for (int i = 0; i < loops; ++i) {
31 for (int j = 0; j < M; ++j) {
32 ref.ref();
33 ref.unref();
34 }
35 }
36 }
37
38private:
39 using INHERITED = Benchmark;
40};
41
42class PlacedRefCnt : public SkRefCnt {
43public:
45 void operator delete(void*) { }
46
47private:
48 using INHERITED = SkRefCnt;
49};
50
52public:
53 bool isSuitableFor(Backend backend) override {
55 }
56
57protected:
58 const char* onGetName() override {
59 return "ref_cnt_heap";
60 }
61
62 void onDraw(int loops, SkCanvas*) override {
63 char memory[sizeof(PlacedRefCnt)];
64 for (int i = 0; i < loops; ++i) {
65 PlacedRefCnt* ref = new (memory) PlacedRefCnt();
66 for (int j = 0; j < M; ++j) {
67 ref->ref();
68 ref->unref();
69 }
70 ref->unref();
71 }
72 }
73
74private:
75 using INHERITED = Benchmark;
76};
77
78class RefCntBench_New : public Benchmark {
79public:
80 bool isSuitableFor(Backend backend) override {
82 }
83
84protected:
85 const char* onGetName() override {
86 return "ref_cnt_new";
87 }
88
89 void onDraw(int loops, SkCanvas*) override {
90 for (int i = 0; i < loops; ++i) {
91 SkRefCnt* ref = new SkRefCnt();
92 for (int j = 0; j < M; ++j) {
93 ref->ref();
94 ref->unref();
95 }
96 ref->unref();
97 }
98 }
99
100private:
101 using INHERITED = Benchmark;
102};
103
104///////////////////////////////////////////////////////////////////////////////
105
107public:
110 }
111
112protected:
113 const char* onGetName() override {
114 return "ref_cnt_stack_weak";
115 }
116
117 void onDraw(int loops, SkCanvas*) override {
118 for (int i = 0; i < loops; ++i) {
120 for (int j = 0; j < M; ++j) {
121 ref.ref();
122 ref.unref();
123 }
124 }
125 }
126
127private:
128 using INHERITED = Benchmark;
129};
130
132public:
134 void operator delete(void*) { }
135};
136
138public:
141 }
142
143protected:
144 const char* onGetName() override {
145 return "ref_cnt_heap_weak";
146 }
147
148 void onDraw(int loops, SkCanvas*) override {
149 char memory[sizeof(PlacedWeakRefCnt)];
150 for (int i = 0; i < loops; ++i) {
151 PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
152 for (int j = 0; j < M; ++j) {
153 ref->ref();
154 ref->unref();
155 }
156 ref->unref();
157 }
158 }
159
160private:
161 using INHERITED = Benchmark;
162};
163
165public:
168 }
169
170protected:
171 const char* onGetName() override {
172 return "ref_cnt_new_weak";
173 }
174
175 void onDraw(int loops, SkCanvas*) override {
176 for (int i = 0; i < loops; ++i) {
178 for (int j = 0; j < M; ++j) {
179 ref->ref();
180 ref->unref();
181 }
182 ref->unref();
183 }
184 }
185
186private:
187 using INHERITED = Benchmark;
188};
189
190///////////////////////////////////////////////////////////////////////////////
191
192DEF_BENCH( return new RefCntBench_Stack(); )
193DEF_BENCH( return new RefCntBench_Heap(); )
194DEF_BENCH( return new RefCntBench_New(); )
195
196DEF_BENCH( return new WeakRefCntBench_Stack(); )
197DEF_BENCH( return new WeakRefCntBench_Heap(); )
198DEF_BENCH( return new WeakRefCntBench_New(); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
@ M
Definition: RefCntBench.cpp:14
const char * onGetName() override
Definition: RefCntBench.cpp:58
bool isSuitableFor(Backend backend) override
Definition: RefCntBench.cpp:53
void onDraw(int loops, SkCanvas *) override
Definition: RefCntBench.cpp:62
const char * onGetName() override
Definition: RefCntBench.cpp:85
bool isSuitableFor(Backend backend) override
Definition: RefCntBench.cpp:80
void onDraw(int loops, SkCanvas *) override
Definition: RefCntBench.cpp:89
void onDraw(int loops, SkCanvas *) override
Definition: RefCntBench.cpp:28
bool isSuitableFor(Backend backend) override
Definition: RefCntBench.cpp:19
const char * onGetName() override
Definition: RefCntBench.cpp:24
friend class SkWeakRefCnt
Definition: SkRefCnt.h:104
void ref() const
Definition: SkRefCnt.h:62
void onDraw(int loops, SkCanvas *) override
bool isSuitableFor(Backend backend) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *) override
bool isSuitableFor(Backend backend) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *) override
bool isSuitableFor(Backend backend) override
const char * onGetName() override