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 "bench/Benchmark.h"
9 #include "include/private/SkTemplates.h"
10 #include "src/core/SkUtils.h"
11
12 template <typename T>
13 class MemsetBench : public Benchmark {
14 public:
MemsetBench(size_t bytes)15 explicit MemsetBench(size_t bytes)
16 : fN(bytes / sizeof(T))
17 , fBuffer(fN)
18 , fName(SkStringPrintf("memset%zu_%zu", sizeof(T)*8, bytes)) {}
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<uint64_t>::onDraw(int loops, SkCanvas*) {
32 for (int i = 0; i < 1000*loops; i++) {
33 sk_memset64(fBuffer.get(), 0xFACEFACEFACEFACE, fN);
34 }
35 }
36
onDraw(int loops,SkCanvas *)37 template <> void MemsetBench<uint32_t>::onDraw(int loops, SkCanvas*) {
38 for (int i = 0; i < 1000*loops; i++) {
39 sk_memset32(fBuffer.get(), 0xFACEB004, fN);
40 }
41 }
42
onDraw(int loops,SkCanvas *)43 template <> void MemsetBench<uint16_t>::onDraw(int loops, SkCanvas*) {
44 for (int i = 0; i < 1000*loops; i++) {
45 sk_memset16(fBuffer.get(), 0x4973, fN);
46 }
47 }
48
49 DEF_BENCH(return (new MemsetBench<uint64_t>(16)));
50 DEF_BENCH(return (new MemsetBench<uint64_t>(64)));
51 DEF_BENCH(return (new MemsetBench<uint64_t>(256)));
52 DEF_BENCH(return (new MemsetBench<uint64_t>(512)));
53 DEF_BENCH(return (new MemsetBench<uint64_t>(768)));
54 DEF_BENCH(return (new MemsetBench<uint64_t>(1024)));
55 DEF_BENCH(return (new MemsetBench<uint64_t>(2048)));
56 DEF_BENCH(return (new MemsetBench<uint64_t>(4096)));
57 DEF_BENCH(return (new MemsetBench<uint64_t>(65536)));
58
59 DEF_BENCH(return (new MemsetBench<uint32_t>(16)));
60 DEF_BENCH(return (new MemsetBench<uint32_t>(64)));
61 DEF_BENCH(return (new MemsetBench<uint32_t>(256)));
62 DEF_BENCH(return (new MemsetBench<uint32_t>(512)));
63 DEF_BENCH(return (new MemsetBench<uint32_t>(768)));
64 DEF_BENCH(return (new MemsetBench<uint32_t>(1024)));
65 DEF_BENCH(return (new MemsetBench<uint32_t>(2048)));
66 DEF_BENCH(return (new MemsetBench<uint32_t>(4096)));
67 DEF_BENCH(return (new MemsetBench<uint32_t>(65536)));
68
69 DEF_BENCH(return (new MemsetBench<uint16_t>(16)));
70 DEF_BENCH(return (new MemsetBench<uint16_t>(64)));
71 DEF_BENCH(return (new MemsetBench<uint16_t>(256)));
72 DEF_BENCH(return (new MemsetBench<uint16_t>(512)));
73 DEF_BENCH(return (new MemsetBench<uint16_t>(768)));
74 DEF_BENCH(return (new MemsetBench<uint16_t>(1024)));
75 DEF_BENCH(return (new MemsetBench<uint16_t>(2048)));
76 DEF_BENCH(return (new MemsetBench<uint16_t>(4096)));
77 DEF_BENCH(return (new MemsetBench<uint16_t>(65536)));
78