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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2015-07-07 19:21:21 +00:00
|
|
|
#include "SkMutex.h"
|
2015-09-18 16:24:18 +00:00
|
|
|
#include "SkSharedMutex.h"
|
|
|
|
#include "SkSpinlock.h"
|
|
|
|
#include "SkString.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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
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
|
|
|
};
|
|
|
|
|
2015-09-18 17:50:35 +00:00
|
|
|
class SharedBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return "SkSharedMutexSharedUncontendedBenchmark";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2015-09-18 17:50:35 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2015-09-22 17:38:48 +00:00
|
|
|
fMu.acquireShared();
|
|
|
|
fMu.releaseShared();
|
2015-09-18 17:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
2015-09-22 17:38:48 +00:00
|
|
|
SkSharedMutex fMu;
|
2015-09-18 17:50:35 +00:00
|
|
|
};
|
|
|
|
|
2011-11-14 17:30:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-09-18 16:24:18 +00:00
|
|
|
DEF_BENCH( return new MutexBench<SkSharedMutex>(SkString("SkSharedMutex")); )
|
|
|
|
DEF_BENCH( return new MutexBench<SkMutex>(SkString("SkMutex")); )
|
|
|
|
DEF_BENCH( return new MutexBench<SkSpinlock>(SkString("SkSpinlock")); )
|
2015-09-18 17:50:35 +00:00
|
|
|
DEF_BENCH( return new SharedBench; )
|
|
|
|
|