2012-05-14 14:09:24 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2012-05-16 18:21:56 +00:00
|
|
|
#include "SkRefCnt.h"
|
2012-05-14 14:09:24 +00:00
|
|
|
#include "SkThread.h"
|
2012-05-16 18:21:56 +00:00
|
|
|
#include "SkWeakRefCnt.h"
|
2012-05-14 14:09:24 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
M = 2
|
2012-05-14 14:09:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RefCntBench_Stack : public SkBenchmark {
|
|
|
|
public:
|
|
|
|
RefCntBench_Stack(void* param) : INHERITED(param) {
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-05-14 14:09:24 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_stack";
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
2012-05-14 14:09:24 +00:00
|
|
|
SkRefCnt ref;
|
|
|
|
for (int j = 0; j < M; ++j) {
|
|
|
|
ref.ref();
|
|
|
|
ref.unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlacedRefCnt : public SkRefCnt {
|
|
|
|
public:
|
2012-06-21 20:25:03 +00:00
|
|
|
SK_DECLARE_INST_COUNT(PlacedRefCnt)
|
|
|
|
|
2012-05-14 14:09:24 +00:00
|
|
|
PlacedRefCnt() : SkRefCnt() { }
|
2013-03-05 18:50:01 +00:00
|
|
|
void operator delete(void*) { }
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2012-05-14 14:09:24 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 20:25:03 +00:00
|
|
|
SK_DEFINE_INST_COUNT(PlacedRefCnt)
|
|
|
|
|
2012-05-14 14:09:24 +00:00
|
|
|
class RefCntBench_Heap : public SkBenchmark {
|
|
|
|
public:
|
|
|
|
RefCntBench_Heap(void* param) : INHERITED(param) {
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-05-14 14:09:24 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_heap";
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2012-05-14 14:09:24 +00:00
|
|
|
char memory[sizeof(PlacedRefCnt)];
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
2012-05-14 14:09:24 +00:00
|
|
|
PlacedRefCnt* ref = new (memory) PlacedRefCnt();
|
|
|
|
for (int j = 0; j < M; ++j) {
|
|
|
|
ref->ref();
|
|
|
|
ref->unref();
|
|
|
|
}
|
|
|
|
ref->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
class RefCntBench_New : public SkBenchmark {
|
|
|
|
public:
|
|
|
|
RefCntBench_New(void* param) : INHERITED(param) {
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_new";
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
2012-05-16 18:21:56 +00:00
|
|
|
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) {
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_stack_weak";
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
2012-05-16 18:21:56 +00:00
|
|
|
SkWeakRefCnt ref;
|
|
|
|
for (int j = 0; j < M; ++j) {
|
|
|
|
ref.ref();
|
|
|
|
ref.unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlacedWeakRefCnt : public SkWeakRefCnt {
|
|
|
|
public:
|
|
|
|
PlacedWeakRefCnt() : SkWeakRefCnt() { }
|
2013-03-05 18:50:01 +00:00
|
|
|
void operator delete(void*) { }
|
2012-05-16 18:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WeakRefCntBench_Heap : public SkBenchmark {
|
|
|
|
public:
|
|
|
|
WeakRefCntBench_Heap(void* param) : INHERITED(param) {
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_heap_weak";
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2012-05-16 18:21:56 +00:00
|
|
|
char memory[sizeof(PlacedWeakRefCnt)];
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
2012-05-16 18:21:56 +00:00
|
|
|
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) {
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_new_weak";
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
2012-05-16 18:21:56 +00:00
|
|
|
SkWeakRefCnt* ref = new SkWeakRefCnt();
|
|
|
|
for (int j = 0; j < M; ++j) {
|
|
|
|
ref->ref();
|
|
|
|
ref->unref();
|
|
|
|
}
|
|
|
|
ref->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-05-14 14:09:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
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); }
|
2012-05-14 14:09:24 +00:00
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
static BenchRegistry gReg00(Fact00);
|
|
|
|
static BenchRegistry gReg01(Fact01);
|
|
|
|
static BenchRegistry gReg02(Fact02);
|
2012-05-14 14:09:24 +00:00
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
static BenchRegistry gReg10(Fact10);
|
|
|
|
static BenchRegistry gReg11(Fact11);
|
|
|
|
static BenchRegistry gReg12(Fact12);
|