aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/RefCntBench.cpp
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-16 18:21:56 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-16 18:21:56 +0000
commita02bc1519cf49afa31fb38bed097dd5014880d04 (patch)
tree64d0638ce6c287317467d07bb5f7aeeb290d7940 /bench/RefCntBench.cpp
parentb2aacb6dc29f853e3f37fad208ad8fe8c8138a03 (diff)
WeakRefCnt
Diffstat (limited to 'bench/RefCntBench.cpp')
-rw-r--r--bench/RefCntBench.cpp123
1 files changed, 119 insertions, 4 deletions
diff --git a/bench/RefCntBench.cpp b/bench/RefCntBench.cpp
index 44fb648f4e..f21317a21a 100644
--- a/bench/RefCntBench.cpp
+++ b/bench/RefCntBench.cpp
@@ -5,7 +5,9 @@
* found in the LICENSE file.
*/
#include "SkBenchmark.h"
+#include "SkRefCnt.h"
#include "SkThread.h"
+#include "SkWeakRefCnt.h"
#include <memory>
enum {
@@ -67,11 +69,124 @@ private:
typedef SkBenchmark INHERITED;
};
+class RefCntBench_New : public SkBenchmark {
+public:
+ RefCntBench_New(void* param) : INHERITED(param) {
+ }
+protected:
+ virtual const char* onGetName() {
+ return "ref_cnt_new";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ for (int i = 0; i < N; ++i) {
+ SkRefCnt* ref = new SkRefCnt();
+ for (int j = 0; j < M; ++j) {
+ ref->ref();
+ ref->unref();
+ }
+ ref->unref();
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class WeakRefCntBench_Stack : public SkBenchmark {
+public:
+ WeakRefCntBench_Stack(void* param) : INHERITED(param) {
+ }
+protected:
+ virtual const char* onGetName() {
+ return "ref_cnt_stack_weak";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ for (int i = 0; i < N; ++i) {
+ SkWeakRefCnt ref;
+ for (int j = 0; j < M; ++j) {
+ ref.ref();
+ ref.unref();
+ }
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+class PlacedWeakRefCnt : public SkWeakRefCnt {
+public:
+ PlacedWeakRefCnt() : SkWeakRefCnt() { }
+ void operator delete(void *p) { }
+};
+
+class WeakRefCntBench_Heap : public SkBenchmark {
+public:
+ WeakRefCntBench_Heap(void* param) : INHERITED(param) {
+ }
+protected:
+ virtual const char* onGetName() {
+ return "ref_cnt_heap_weak";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ char memory[sizeof(PlacedWeakRefCnt)];
+ for (int i = 0; i < N; ++i) {
+ PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
+ for (int j = 0; j < M; ++j) {
+ ref->ref();
+ ref->unref();
+ }
+ ref->unref();
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+class WeakRefCntBench_New : public SkBenchmark {
+public:
+ WeakRefCntBench_New(void* param) : INHERITED(param) {
+ }
+protected:
+ virtual const char* onGetName() {
+ return "ref_cnt_new_weak";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ for (int i = 0; i < N; ++i) {
+ SkWeakRefCnt* ref = new SkWeakRefCnt();
+ for (int j = 0; j < M; ++j) {
+ ref->ref();
+ ref->unref();
+ }
+ ref->unref();
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
///////////////////////////////////////////////////////////////////////////////
-static SkBenchmark* Fact0(void* p) { return new RefCntBench_Stack(p); }
-static SkBenchmark* Fact1(void* p) { return new RefCntBench_Heap(p); }
+static SkBenchmark* Fact00(void* p) { return new RefCntBench_Stack(p); }
+static SkBenchmark* Fact01(void* p) { return new RefCntBench_Heap(p); }
+static SkBenchmark* Fact02(void* p) { return new RefCntBench_New(p); }
+
+static SkBenchmark* Fact10(void* p) { return new WeakRefCntBench_Stack(p); }
+static SkBenchmark* Fact11(void* p) { return new WeakRefCntBench_Heap(p); }
+static SkBenchmark* Fact12(void* p) { return new WeakRefCntBench_New(p); }
-static BenchRegistry gReg01(Fact0);
-static BenchRegistry gReg02(Fact1);
+static BenchRegistry gReg00(Fact00);
+static BenchRegistry gReg01(Fact01);
+static BenchRegistry gReg02(Fact02);
+static BenchRegistry gReg10(Fact10);
+static BenchRegistry gReg11(Fact11);
+static BenchRegistry gReg12(Fact12);