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" |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 9 | #include "SkTemplates.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 10 | #include "SkUtils.h" |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 11 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 12 | template <typename T, bool kInline> |
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 | public: |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 15 | explicit MemsetBench(int n) |
| 16 | : fN(n) |
| 17 | , fBuffer(n) |
| 18 | , fName(SkStringPrintf("memset%d_%d%s", sizeof(T)*8, n, kInline ? "_inline" : "")) {} |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 19 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 20 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 21 | const char* onGetName() override { return fName.c_str(); } |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 22 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 23 | void onDraw(const int loops, SkCanvas*) override; |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 24 | |
| 25 | private: |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 26 | int fN; |
| 27 | SkAutoTMalloc<T> fBuffer; |
| 28 | SkString fName; |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 31 | template <> void MemsetBench<uint32_t, false>::onDraw(const int loops, SkCanvas*) { |
| 32 | for (int i = 0; i < 1000*loops; i++) { |
| 33 | sk_memset32(fBuffer.get(), 0xFACEB004, fN); |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 34 | } |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 35 | } |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 36 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 37 | template <> void MemsetBench<uint16_t, false>::onDraw(const int loops, SkCanvas*) { |
| 38 | for (int i = 0; i < 1000*loops; i++) { |
| 39 | sk_memset16(fBuffer.get(), 0x4973, fN); |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 40 | } |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 41 | } |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 42 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 43 | template <typename T> |
| 44 | static void memsetT(T* dst, T val, int n) { |
| 45 | for (int i = 0; i < n; i++) { dst[i] = val; } |
| 46 | } |
reed@google.com | c117cba | 2013-06-03 16:54:10 +0000 | [diff] [blame] | 47 | |
mtklein | 9ff378b | 2015-04-09 14:05:17 -0700 | [diff] [blame] | 48 | template <> void MemsetBench<uint32_t, true>::onDraw(const int loops, SkCanvas*) { |
| 49 | for (int i = 0; i < 1000*loops; i++) { |
| 50 | memsetT<uint32_t>(fBuffer.get(), 0xFACEB004, fN); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | template <> void MemsetBench<uint16_t, true>::onDraw(const int loops, SkCanvas*) { |
| 55 | for (int i = 0; i < 1000*loops; i++) { |
| 56 | memsetT<uint16_t>(fBuffer.get(), 0x4973, fN); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | DEF_BENCH(return (new MemsetBench<uint32_t, true>(1))); |
| 61 | DEF_BENCH(return (new MemsetBench<uint32_t, false>(1))); |
| 62 | DEF_BENCH(return (new MemsetBench<uint32_t, true>(10))); |
| 63 | DEF_BENCH(return (new MemsetBench<uint32_t, false>(10))); |
| 64 | DEF_BENCH(return (new MemsetBench<uint32_t, true>(100))); |
| 65 | DEF_BENCH(return (new MemsetBench<uint32_t, false>(100))); |
| 66 | DEF_BENCH(return (new MemsetBench<uint32_t, true>(1000))); |
| 67 | DEF_BENCH(return (new MemsetBench<uint32_t, false>(1000))); |
| 68 | DEF_BENCH(return (new MemsetBench<uint32_t, true>(10000))); |
| 69 | DEF_BENCH(return (new MemsetBench<uint32_t, false>(10000))); |
| 70 | DEF_BENCH(return (new MemsetBench<uint32_t, true>(100000))); |
| 71 | DEF_BENCH(return (new MemsetBench<uint32_t, false>(100000))); |
| 72 | |
| 73 | DEF_BENCH(return (new MemsetBench<uint16_t, true>(1))); |
| 74 | DEF_BENCH(return (new MemsetBench<uint16_t, false>(1))); |
| 75 | DEF_BENCH(return (new MemsetBench<uint16_t, true>(10))); |
| 76 | DEF_BENCH(return (new MemsetBench<uint16_t, false>(10))); |
| 77 | DEF_BENCH(return (new MemsetBench<uint16_t, true>(100))); |
| 78 | DEF_BENCH(return (new MemsetBench<uint16_t, false>(100))); |
| 79 | DEF_BENCH(return (new MemsetBench<uint16_t, true>(1000))); |
| 80 | DEF_BENCH(return (new MemsetBench<uint16_t, false>(1000))); |
| 81 | DEF_BENCH(return (new MemsetBench<uint16_t, true>(10000))); |
| 82 | DEF_BENCH(return (new MemsetBench<uint16_t, false>(10000))); |
| 83 | DEF_BENCH(return (new MemsetBench<uint16_t, true>(100000))); |
| 84 | DEF_BENCH(return (new MemsetBench<uint16_t, false>(100000))); |