• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "Benchmark.h"
9 #include "SkTemplates.h"
10 #include "SkUtils.h"
11 
12 template <typename T, bool kInline>
13 class MemsetBench : public Benchmark {
14 public:
MemsetBench(int n)15     explicit MemsetBench(int n)
16         : fN(n)
17         , fBuffer(n)
18         , fName(SkStringPrintf("memset%d_%d%s", sizeof(T)*8, n, kInline ? "_inline" : "")) {}
19 
isSuitableFor(Backend backend)20     bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
onGetName()21     const char* onGetName() override { return fName.c_str(); }
22 
23     void onDraw(int loops, SkCanvas*) override;
24 
25 private:
26     int fN;
27     SkAutoTMalloc<T> fBuffer;
28     SkString fName;
29 };
30 
onDraw(int loops,SkCanvas *)31 template <> void MemsetBench<uint32_t, false>::onDraw(int loops, SkCanvas*) {
32     for (int i = 0; i < 1000*loops; i++) {
33         sk_memset32(fBuffer.get(), 0xFACEB004, fN);
34     }
35 }
36 
onDraw(int loops,SkCanvas *)37 template <> void MemsetBench<uint16_t, false>::onDraw(int loops, SkCanvas*) {
38     for (int i = 0; i < 1000*loops; i++) {
39         sk_memset16(fBuffer.get(), 0x4973, fN);
40     }
41 }
42 
43 template <typename T>
memsetT(T * dst,T val,int n)44 static void memsetT(T* dst, T val, int n) {
45     for (int i = 0; i < n; i++) { dst[i] = val; }
46 }
47 
onDraw(int loops,SkCanvas *)48 template <> void MemsetBench<uint32_t, true>::onDraw(int loops, SkCanvas*) {
49     for (int i = 0; i < 1000*loops; i++) {
50         memsetT<uint32_t>(fBuffer.get(), 0xFACEB004, fN);
51     }
52 }
53 
onDraw(int loops,SkCanvas *)54 template <> void MemsetBench<uint16_t, true>::onDraw(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)));
85