2011-11-14 17:30:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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/SkString.h"
|
|
|
|
#include "include/private/SkMutex.h"
|
|
|
|
#include "include/private/SkSpinlock.h"
|
2020-04-29 18:50:26 +00:00
|
|
|
#include "src/core/SkSharedMutex.h"
|
2011-11-14 17:30:08 +00:00
|
|
|
|
2015-09-18 16:24:18 +00:00
|
|
|
template <typename Mutex>
|
2014-06-19 19:32:29 +00:00
|
|
|
class MutexBench : public Benchmark {
|
2011-11-14 17:30:08 +00:00
|
|
|
public:
|
2015-09-18 16:24:18 +00:00
|
|
|
MutexBench(SkString benchPrefix) : fBenchName(benchPrefix += "UncontendedBenchmark") { }
|
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;
|
2011-11-14 17:30:08 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2011-11-14 17:30:08 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2015-09-18 16:24:18 +00:00
|
|
|
return fBenchName.c_str();
|
2011-11-14 17:30:08 +00:00
|
|
|
}
|
|
|
|
|
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++) {
|
2015-09-22 17:38:48 +00:00
|
|
|
fMu.acquire();
|
|
|
|
fMu.release();
|
2011-11-14 17:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2015-09-18 16:24:18 +00:00
|
|
|
SkString fBenchName;
|
2015-09-22 17:38:48 +00:00
|
|
|
Mutex fMu;
|
2011-11-14 17:30:08 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 18:50:26 +00:00
|
|
|
class SharedBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return "SkSharedMutexSharedUncontendedBenchmark";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
fMu.acquireShared();
|
|
|
|
fMu.releaseShared();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2020-04-29 18:50:26 +00:00
|
|
|
SkSharedMutex fMu;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_BENCH( return new MutexBench<SkSharedMutex>(SkString("SkSharedMutex")); )
|
2015-09-18 16:24:18 +00:00
|
|
|
DEF_BENCH( return new MutexBench<SkMutex>(SkString("SkMutex")); )
|
|
|
|
DEF_BENCH( return new MutexBench<SkSpinlock>(SkString("SkSpinlock")); )
|
2020-04-29 18:50:26 +00:00
|
|
|
DEF_BENCH( return new SharedBench; )
|