Flutter Engine
The Flutter Engine
MemsetBench.cpp
Go to the documentation of this file.
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"
10#include "src/core/SkMemset.h"
11
12using namespace skia_private;
13
14template <typename T>
15class MemsetBench : public Benchmark {
16public:
17 explicit MemsetBench(size_t bytes)
18 : fN(bytes / sizeof(T))
19 , fBuffer(fN)
20 , fName(SkStringPrintf("memset%zu_%zu", sizeof(T)*8, bytes)) {}
21
23 const char* onGetName() override { return fName.c_str(); }
24
25 void onDraw(int loops, SkCanvas*) override;
26
27private:
28 int fN;
29 AutoTMalloc<T> fBuffer;
30 SkString fName;
31};
32
33template <> void MemsetBench<uint64_t>::onDraw(int loops, SkCanvas*) {
34 for (int i = 0; i < 1000*loops; i++) {
35 SkOpts::memset64(fBuffer.get(), 0xFACEFACEFACEFACE, fN);
36 }
37}
38
39template <> void MemsetBench<uint32_t>::onDraw(int loops, SkCanvas*) {
40 for (int i = 0; i < 1000*loops; i++) {
41 SkOpts::memset32(fBuffer.get(), 0xFACEB004, fN);
42 }
43}
44
45template <> void MemsetBench<uint16_t>::onDraw(int loops, SkCanvas*) {
46 for (int i = 0; i < 1000*loops; i++) {
47 SkOpts::memset16(fBuffer.get(), 0x4973, fN);
48 }
49}
50
56DEF_BENCH(return (new MemsetBench<uint64_t>(1024)));
57DEF_BENCH(return (new MemsetBench<uint64_t>(2048)));
58DEF_BENCH(return (new MemsetBench<uint64_t>(4096)));
59DEF_BENCH(return (new MemsetBench<uint64_t>(65536)));
60
66DEF_BENCH(return (new MemsetBench<uint32_t>(1024)));
67DEF_BENCH(return (new MemsetBench<uint32_t>(2048)));
68DEF_BENCH(return (new MemsetBench<uint32_t>(4096)));
69DEF_BENCH(return (new MemsetBench<uint32_t>(65536)));
70
76DEF_BENCH(return (new MemsetBench<uint16_t>(1024)));
77DEF_BENCH(return (new MemsetBench<uint16_t>(2048)));
78DEF_BENCH(return (new MemsetBench<uint16_t>(4096)));
79DEF_BENCH(return (new MemsetBench<uint16_t>(65536)));
const char * backend
DEF_BENCH(return(new MemsetBench< uint64_t >(16)))
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
bool isSuitableFor(Backend backend) override
Definition: MemsetBench.cpp:22
void onDraw(int loops, SkCanvas *) override
const char * onGetName() override
Definition: MemsetBench.cpp:23
MemsetBench(size_t bytes)
Definition: MemsetBench.cpp:17
const char * c_str() const
Definition: SkString.h:133
void(* memset64)(uint64_t[], uint64_t, int)
void(* memset16)(uint16_t[], uint16_t, int)
void(* memset32)(uint32_t[], uint32_t, int)
#define T
Definition: precompiler.cc:65