| 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(const int loops, SkCanvas*) override { |
| 27 Mutex mu; | |
| 28 for (int i = 0; i < loops; i++) { | 27 for (int i = 0; i < loops; i++) { |
| 29 mu.acquire(); | 28 fMu.acquire(); |
| 30 mu.release(); | 29 fMu.release(); |
| 31 } | 30 } |
| 32 } | 31 } |
| 33 | 32 |
| 34 private: | 33 private: |
| 35 typedef Benchmark INHERITED; | 34 typedef Benchmark INHERITED; |
| 36 SkString fBenchName; | 35 SkString fBenchName; |
| 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(const int loops, SkCanvas*) override { |
| 51 SkSharedMutex mu; | |
| 52 for (int i = 0; i < loops; i++) { | 51 for (int i = 0; i < loops; i++) { |
| 53 mu.acquireShared(); | 52 fMu.acquireShared(); |
| 54 mu.releaseShared(); | 53 fMu.releaseShared(); |
| 55 } | 54 } |
| 56 } | 55 } |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 typedef Benchmark INHERITED; | 58 typedef Benchmark INHERITED; |
| 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 |