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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/private/SkWeakRefCnt.h"
|
2018-06-11 14:45:26 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <new>
|
2012-05-14 14:09:24 +00:00
|
|
|
|
|
|
|
enum {
|
2013-09-10 19:23:38 +00:00
|
|
|
M = 2
|
2012-05-14 14:09:24 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RefCntBench_Stack : public Benchmark {
|
2012-05-14 14:09:24 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
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:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-14 14:09:24 +00:00
|
|
|
return "ref_cnt_stack";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-14 14:09:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PlacedRefCnt : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RefCntBench_Heap : public Benchmark {
|
2012-05-14 14:09:24 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
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:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-14 14:09:24 +00:00
|
|
|
return "ref_cnt_heap";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-14 14:09:24 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RefCntBench_New : public Benchmark {
|
2012-05-16 18:21:56 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
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:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-16 18:21:56 +00:00
|
|
|
return "ref_cnt_new";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-16 18:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class WeakRefCntBench_Stack : public Benchmark {
|
2012-05-16 18:21:56 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
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:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-16 18:21:56 +00:00
|
|
|
return "ref_cnt_stack_weak";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-16 18:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class WeakRefCntBench_Heap : public Benchmark {
|
2012-05-16 18:21:56 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
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:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-16 18:21:56 +00:00
|
|
|
return "ref_cnt_heap_weak";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-16 18:21:56 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class WeakRefCntBench_New : public Benchmark {
|
2012-05-16 18:21:56 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
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:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-16 18:21:56 +00:00
|
|
|
return "ref_cnt_new_weak";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-16 18:21:56 +00:00
|
|
|
};
|
|
|
|
|
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(); )
|