tomhudson@google.com | 410e9dc | 2011-11-14 17:30:08 +0000 | [diff] [blame] | 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 "SkBenchmark.h" |
| 8 | #include "SkThread.h" |
| 9 | |
| 10 | class MutexBench : public SkBenchmark { |
| 11 | enum { |
| 12 | N = SkBENCHLOOP(80), |
| 13 | M = SkBENCHLOOP(200) |
| 14 | }; |
| 15 | public: |
| 16 | MutexBench(void* param) : INHERITED(param) { |
robertphillips@google.com | 433ce5e | 2012-09-17 10:49:30 +0000 | [diff] [blame] | 17 | fIsRendering = false; |
tomhudson@google.com | 410e9dc | 2011-11-14 17:30:08 +0000 | [diff] [blame] | 18 | } |
| 19 | protected: |
| 20 | virtual const char* onGetName() { |
| 21 | return "mutex"; |
| 22 | } |
| 23 | |
| 24 | virtual void onDraw(SkCanvas* canvas) { |
| 25 | for (int i = 0; i < N; i++) { |
digit@google.com | 1771cbf | 2012-01-26 21:26:40 +0000 | [diff] [blame] | 26 | SK_DECLARE_STATIC_MUTEX(mu); |
tomhudson@google.com | 410e9dc | 2011-11-14 17:30:08 +0000 | [diff] [blame] | 27 | for (int j = 0; j < M; j++) { |
| 28 | mu.acquire(); |
| 29 | mu.release(); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | private: |
| 35 | typedef SkBenchmark INHERITED; |
| 36 | }; |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | static SkBenchmark* Fact(void* p) { return new MutexBench(p); } |
| 41 | |
| 42 | static BenchRegistry gReg01(Fact); |