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-14 14:09:24 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-14 14:09:24 +0000
commit554875210043b34178f7ed6ac5bd682b1fad367b (patch)
treefdadeb167ef502f98784117a3c05378c72fceeec /bench/RefCntBench.cpp
parentf105b109264f71dfb0bfd9977e6a5dd0a5a12f57 (diff)
Add bench and test for SkRefCnt.
http://codereview.appspot.com/6195071/ This also adds a cross platform SkThread for testing purposes. git-svn-id: http://skia.googlecode.com/svn/trunk@3921 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/RefCntBench.cpp')
-rw-r--r--bench/RefCntBench.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/bench/RefCntBench.cpp b/bench/RefCntBench.cpp
new file mode 100644
index 0000000000..44fb648f4e
--- /dev/null
+++ b/bench/RefCntBench.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkBenchmark.h"
+#include "SkThread.h"
+#include <memory>
+
+enum {
+ N = SkBENCHLOOP(1000000),
+ M = SkBENCHLOOP(2)
+};
+
+class RefCntBench_Stack : public SkBenchmark {
+public:
+ RefCntBench_Stack(void* param) : INHERITED(param) {
+ }
+protected:
+ virtual const char* onGetName() {
+ return "ref_cnt_stack";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ for (int i = 0; i < N; ++i) {
+ SkRefCnt ref;
+ for (int j = 0; j < M; ++j) {
+ ref.ref();
+ ref.unref();
+ }
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+class PlacedRefCnt : public SkRefCnt {
+public:
+ PlacedRefCnt() : SkRefCnt() { }
+ void operator delete(void *p) { }
+};
+
+class RefCntBench_Heap : public SkBenchmark {
+public:
+ RefCntBench_Heap(void* param) : INHERITED(param) {
+ }
+protected:
+ virtual const char* onGetName() {
+ return "ref_cnt_heap";
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ char memory[sizeof(PlacedRefCnt)];
+ for (int i = 0; i < N; ++i) {
+ PlacedRefCnt* ref = new (memory) PlacedRefCnt();
+ 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 BenchRegistry gReg01(Fact0);
+static BenchRegistry gReg02(Fact1);
+