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