OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkTemplates.h" |
10 #include "SkString.h" | |
11 #include "SkUtils.h" | 10 #include "SkUtils.h" |
12 | 11 |
| 12 template <typename T, bool kInline> |
13 class MemsetBench : public Benchmark { | 13 class MemsetBench : public Benchmark { |
14 SkString fName; | 14 public: |
| 15 explicit MemsetBench(int n) |
| 16 : fN(n) |
| 17 , fBuffer(n) |
| 18 , fName(SkStringPrintf("memset%d_%d%s", sizeof(T)*8, n, kInline ? "_inli
ne" : "")) {} |
15 | 19 |
16 protected: | 20 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
17 int fMinSize; | 21 const char* onGetName() override { return fName.c_str(); } |
18 int fMaxSize; | |
19 enum { | |
20 kBufferSize = 10000, | |
21 VALUE32 = 0x12345678, | |
22 VALUE16 = 0x1234 | |
23 }; | |
24 | 22 |
25 enum MemsetType { | 23 void onDraw(const int loops, SkCanvas*) override; |
26 MEMSET16 = 16, | |
27 MEMSET32 = 32 | |
28 }; | |
29 | |
30 public: | |
31 MemsetBench(MemsetType type, int minSize, int maxSize) { | |
32 SkASSERT((minSize < maxSize) && (maxSize <= kBufferSize)); | |
33 fMinSize = minSize; | |
34 fMaxSize = maxSize; | |
35 fName.printf("memset%d_%d_%d", type, minSize, maxSize); | |
36 } | |
37 | |
38 bool isSuitableFor(Backend backend) override { | |
39 return backend == kNonRendering_Backend; | |
40 } | |
41 | |
42 virtual void performTest() = 0; | |
43 | |
44 protected: | |
45 const char* onGetName() override { | |
46 return fName.c_str(); | |
47 } | |
48 | |
49 void onDraw(const int loops, SkCanvas* canvas) override { | |
50 for (int i = 0; i < loops; ++i) { | |
51 this->performTest(); | |
52 } | |
53 } | |
54 | 24 |
55 private: | 25 private: |
56 typedef Benchmark INHERITED; | 26 int fN; |
| 27 SkAutoTMalloc<T> fBuffer; |
| 28 SkString fName; |
57 }; | 29 }; |
58 | 30 |
59 class Memset32Bench : public MemsetBench { | 31 template <> void MemsetBench<uint32_t, false>::onDraw(const int loops, SkCanvas*
) { |
60 uint32_t kBuffer[kBufferSize + 3]; | 32 for (int i = 0; i < 1000*loops; i++) { |
61 public: | 33 sk_memset32(fBuffer.get(), 0xFACEB004, fN); |
62 Memset32Bench(int minSize, int maxSize) | 34 } |
63 : INHERITED(MEMSET32, minSize, maxSize) {} | 35 } |
64 | 36 |
65 protected: | 37 template <> void MemsetBench<uint16_t, false>::onDraw(const int loops, SkCanvas*
) { |
66 void performTest() override { | 38 for (int i = 0; i < 1000*loops; i++) { |
67 for(int j = fMinSize; j < fMaxSize; ++j){ | 39 sk_memset16(fBuffer.get(), 0x4973, fN); |
68 sk_memset32(kBuffer, VALUE32, j); | |
69 sk_memset32(kBuffer + 1, VALUE32, j); | |
70 sk_memset32(kBuffer + 2, VALUE32, j); | |
71 sk_memset32(kBuffer + 3, VALUE32, j); | |
72 } | |
73 } | 40 } |
74 private: | 41 } |
75 typedef MemsetBench INHERITED; | |
76 }; | |
77 | 42 |
78 class Memset16Bench : public MemsetBench { | 43 template <typename T> |
79 uint16_t kBuffer[kBufferSize + 7]; | 44 static void memsetT(T* dst, T val, int n) { |
80 public: | 45 for (int i = 0; i < n; i++) { dst[i] = val; } |
81 Memset16Bench(int minSize, int maxSize) | 46 } |
82 : INHERITED(MEMSET16, minSize, maxSize) {} | |
83 | 47 |
84 protected: | 48 template <> void MemsetBench<uint32_t, true>::onDraw(const int loops, SkCanvas*)
{ |
85 void performTest() override { | 49 for (int i = 0; i < 1000*loops; i++) { |
86 for(int j = fMinSize; j < fMaxSize; ++j){ | 50 memsetT<uint32_t>(fBuffer.get(), 0xFACEB004, fN); |
87 sk_memset16(kBuffer, VALUE16, j); | |
88 sk_memset16(kBuffer + 1, VALUE16, j); | |
89 sk_memset16(kBuffer + 2, VALUE16, j); | |
90 sk_memset16(kBuffer + 3, VALUE16, j); | |
91 sk_memset16(kBuffer + 4, VALUE16, j); | |
92 sk_memset16(kBuffer + 5, VALUE16, j); | |
93 sk_memset16(kBuffer + 6, VALUE16, j); | |
94 sk_memset16(kBuffer + 7, VALUE16, j); | |
95 } | |
96 } | 51 } |
97 private: | 52 } |
98 typedef MemsetBench INHERITED; | |
99 }; | |
100 | 53 |
101 DEF_BENCH(return new Memset32Bench(1, 600);) | 54 template <> void MemsetBench<uint16_t, true>::onDraw(const int loops, SkCanvas*)
{ |
102 DEF_BENCH(return new Memset32Bench(600, 800);) | 55 for (int i = 0; i < 1000*loops; i++) { |
103 DEF_BENCH(return new Memset32Bench(800, 1000);) | 56 memsetT<uint16_t>(fBuffer.get(), 0x4973, fN); |
104 DEF_BENCH(return new Memset32Bench(1000, 2000);) | 57 } |
105 DEF_BENCH(return new Memset32Bench(2000, 3000);) | 58 } |
106 DEF_BENCH(return new Memset32Bench(3000, 4000);) | |
107 DEF_BENCH(return new Memset32Bench(4000, 5000);) | |
108 | 59 |
109 DEF_BENCH(return new Memset16Bench(1, 600);) | 60 DEF_BENCH(return (new MemsetBench<uint32_t, true>(1))); |
110 DEF_BENCH(return new Memset16Bench(600, 800);) | 61 DEF_BENCH(return (new MemsetBench<uint32_t, false>(1))); |
111 DEF_BENCH(return new Memset16Bench(800, 1000);) | 62 DEF_BENCH(return (new MemsetBench<uint32_t, true>(10))); |
112 DEF_BENCH(return new Memset16Bench(1000, 2000);) | 63 DEF_BENCH(return (new MemsetBench<uint32_t, false>(10))); |
113 DEF_BENCH(return new Memset16Bench(2000, 3000);) | 64 DEF_BENCH(return (new MemsetBench<uint32_t, true>(100))); |
114 DEF_BENCH(return new Memset16Bench(3000, 4000);) | 65 DEF_BENCH(return (new MemsetBench<uint32_t, false>(100))); |
115 DEF_BENCH(return new Memset16Bench(4000, 5000);) | 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))); |
OLD | NEW |