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:
|
2013-11-21 06:21:58 +00:00
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-14 14:09:24 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2012-05-14 14:09:24 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_stack";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
|
|
|
for (int i = 0; i < loops; ++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
|
|
|
};
|
|
|
|
|
|
|
|
class RefCntBench_Heap : public SkBenchmark {
|
|
|
|
public:
|
2013-11-21 06:21:58 +00:00
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-14 14:09:24 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2012-05-14 14:09:24 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_heap";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
2012-05-14 14:09:24 +00:00
|
|
|
char memory[sizeof(PlacedRefCnt)];
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++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:
|
2013-11-21 06:21:58 +00:00
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_new";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
|
|
|
for (int i = 0; i < loops; ++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:
|
2013-11-21 06:21:58 +00:00
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_stack_weak";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
|
|
|
for (int i = 0; i < loops; ++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:
|
2013-11-21 06:21:58 +00:00
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_heap_weak";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
2012-05-16 18:21:56 +00:00
|
|
|
char memory[sizeof(PlacedWeakRefCnt)];
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++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:
|
2013-11-21 06:21:58 +00:00
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-16 18:21:56 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2012-05-16 18:21:56 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "ref_cnt_new_weak";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) {
|
|
|
|
for (int i = 0; i < loops; ++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
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new RefCntBench_Stack(); )
|
|
|
|
DEF_BENCH( return new RefCntBench_Heap(); )
|
|
|
|
DEF_BENCH( return new RefCntBench_New(); )
|
2012-05-16 18:21:56 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new WeakRefCntBench_Stack(); )
|
|
|
|
DEF_BENCH( return new WeakRefCntBench_Heap(); )
|
|
|
|
DEF_BENCH( return new WeakRefCntBench_New(); )
|