reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 10 | #include "SkString.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 11 | #include "SkUtils.h" |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 12 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 13 | class MemsetBench : public Benchmark { |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 14 | SkString fName; |
| 15 | |
| 16 | protected: |
| 17 | size_t fMinSize; |
| 18 | size_t fMaxSize; |
| 19 | enum { |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 20 | kBufferSize = 10000, |
| 21 | VALUE32 = 0x12345678, |
| 22 | VALUE16 = 0x1234 |
| 23 | }; |
| 24 | |
| 25 | enum MemsetType { |
| 26 | MEMSET16 = 16, |
| 27 | MEMSET32 = 32 |
| 28 | }; |
| 29 | |
| 30 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 31 | MemsetBench(MemsetType type, size_t minSize, size_t maxSize) { |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 32 | SkASSERT((minSize < maxSize) && (maxSize <= kBufferSize)); |
| 33 | fMinSize = minSize; |
| 34 | fMaxSize = maxSize; |
| 35 | fName.printf("memset%d_" SK_SIZE_T_SPECIFIER "_" SK_SIZE_T_SPECIFIER, |
| 36 | type, minSize, maxSize); |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 40 | return backend == kNonRendering_Backend; |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | virtual void performTest() = 0; |
| 44 | |
| 45 | protected: |
| 46 | virtual const char* onGetName() SK_OVERRIDE { |
| 47 | return fName.c_str(); |
| 48 | } |
| 49 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 50 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 51 | for (int i = 0; i < loops; ++i) { |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 52 | this->performTest(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 57 | typedef Benchmark INHERITED; |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | class Memset32Bench : public MemsetBench { |
| 61 | uint32_t kBuffer[kBufferSize + 3]; |
| 62 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 63 | Memset32Bench(size_t minSize, size_t maxSize) |
| 64 | : INHERITED(MEMSET32, minSize, maxSize) {} |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 65 | |
| 66 | protected: |
robertphillips@google.com | 59ce137 | 2013-06-03 17:29:58 +0000 | [diff] [blame] | 67 | virtual void performTest() SK_OVERRIDE { |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 68 | for(size_t j = fMinSize; j < fMaxSize; ++j){ |
| 69 | sk_memset32(kBuffer, VALUE32, j); |
| 70 | sk_memset32(kBuffer + 1, VALUE32, j); |
| 71 | sk_memset32(kBuffer + 2, VALUE32, j); |
| 72 | sk_memset32(kBuffer + 3, VALUE32, j); |
| 73 | } |
| 74 | } |
| 75 | private: |
| 76 | typedef MemsetBench INHERITED; |
| 77 | }; |
| 78 | |
| 79 | class Memset16Bench : public MemsetBench { |
| 80 | uint16_t kBuffer[kBufferSize + 7]; |
| 81 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 82 | Memset16Bench(size_t minSize, size_t maxSize) |
| 83 | : INHERITED(MEMSET16, minSize, maxSize) {} |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 84 | |
| 85 | protected: |
robertphillips@google.com | 59ce137 | 2013-06-03 17:29:58 +0000 | [diff] [blame] | 86 | virtual void performTest() SK_OVERRIDE { |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 87 | for(size_t j = fMinSize; j < fMaxSize; ++j){ |
| 88 | sk_memset16(kBuffer, VALUE16, j); |
| 89 | sk_memset16(kBuffer + 1, VALUE16, j); |
| 90 | sk_memset16(kBuffer + 2, VALUE16, j); |
| 91 | sk_memset16(kBuffer + 3, VALUE16, j); |
| 92 | sk_memset16(kBuffer + 4, VALUE16, j); |
| 93 | sk_memset16(kBuffer + 5, VALUE16, j); |
| 94 | sk_memset16(kBuffer + 6, VALUE16, j); |
| 95 | sk_memset16(kBuffer + 7, VALUE16, j); |
| 96 | } |
| 97 | } |
| 98 | private: |
| 99 | typedef MemsetBench INHERITED; |
| 100 | }; |
| 101 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 102 | DEF_BENCH(return new Memset32Bench(1, 600);) |
| 103 | DEF_BENCH(return new Memset32Bench(600, 800);) |
| 104 | DEF_BENCH(return new Memset32Bench(800, 1000);) |
| 105 | DEF_BENCH(return new Memset32Bench(1000, 2000);) |
| 106 | DEF_BENCH(return new Memset32Bench(2000, 3000);) |
| 107 | DEF_BENCH(return new Memset32Bench(3000, 4000);) |
| 108 | DEF_BENCH(return new Memset32Bench(4000, 5000);) |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 109 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 110 | DEF_BENCH(return new Memset16Bench(1, 600);) |
| 111 | DEF_BENCH(return new Memset16Bench(600, 800);) |
| 112 | DEF_BENCH(return new Memset16Bench(800, 1000);) |
| 113 | DEF_BENCH(return new Memset16Bench(1000, 2000);) |
| 114 | DEF_BENCH(return new Memset16Bench(2000, 3000);) |
| 115 | DEF_BENCH(return new Memset16Bench(3000, 4000);) |
| 116 | DEF_BENCH(return new Memset16Bench(4000, 5000);) |