Flutter Engine
The Flutter Engine
MutexBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "bench/Benchmark.h"
11#include "src/base/SkSpinlock.h"
12
13template <typename Mutex>
14class MutexBench : public Benchmark {
15public:
16 MutexBench(SkString benchPrefix) : fBenchName(benchPrefix += "UncontendedBenchmark") { }
17 bool isSuitableFor(Backend backend) override {
19 }
20
21protected:
22 const char* onGetName() override {
23 return fBenchName.c_str();
24 }
25
26 void onDraw(int loops, SkCanvas*) override {
27 for (int i = 0; i < loops; i++) {
28 fMu.acquire();
29 fMu.release();
30 }
31 }
32
33private:
34 using INHERITED = Benchmark;
35 SkString fBenchName;
36 Mutex fMu;
37};
38
39class SharedBench : public Benchmark {
40public:
41 bool isSuitableFor(Backend backend) override {
43 }
44
45protected:
46 const char* onGetName() override {
47 return "SkSharedMutexSharedUncontendedBenchmark";
48 }
49
50 void onDraw(int loops, SkCanvas*) override {
51 for (int i = 0; i < loops; i++) {
52 fMu.acquireShared();
53 fMu.releaseShared();
54 }
55 }
56
57private:
58 using INHERITED = Benchmark;
59 SkSharedMutex fMu;
60};
61
62///////////////////////////////////////////////////////////////////////////////
63
64DEF_BENCH( return new MutexBench<SkSharedMutex>(SkString("SkSharedMutex")); )
65DEF_BENCH( return new MutexBench<SkMutex>(SkString("SkMutex")); )
66DEF_BENCH( return new MutexBench<SkSpinlock>(SkString("SkSpinlock")); )
67DEF_BENCH( return new SharedBench; )
const char * backend
DEF_BENCH(return new MutexBench< SkSharedMutex >(SkString("SkSharedMutex"));) DEF_BENCH(return new MutexBench< SkMutex >(SkString("SkMutex"))
const char * onGetName() override
Definition: MutexBench.cpp:22
bool isSuitableFor(Backend backend) override
Definition: MutexBench.cpp:17
void onDraw(int loops, SkCanvas *) override
Definition: MutexBench.cpp:26
MutexBench(SkString benchPrefix)
Definition: MutexBench.cpp:16
void onDraw(int loops, SkCanvas *) override
Definition: MutexBench.cpp:50
bool isSuitableFor(Backend backend) override
Definition: MutexBench.cpp:41
const char * onGetName() override
Definition: MutexBench.cpp:46
const char * c_str() const
Definition: SkString.h:133