blob: ccdbebb646c794eb9a7ecf994c9cd8a487b5ca2c [file] [log] [blame]
reed@google.comc117cba2013-06-03 16:54:10 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/Benchmark.h"
9#include "include/private/SkTemplates.h"
10#include "src/core/SkUtils.h"
reed@google.comc117cba2013-06-03 16:54:10 +000011
mtklein9ff378b2015-04-09 14:05:17 -070012template <typename T, bool kInline>
tfarinaf168b862014-06-19 12:32:29 -070013class MemsetBench : public Benchmark {
reed@google.comc117cba2013-06-03 16:54:10 +000014public:
mtklein9ff378b2015-04-09 14:05:17 -070015 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.org644629c2013-11-21 06:21:58 +000019
mtklein9ff378b2015-04-09 14:05:17 -070020 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
21 const char* onGetName() override { return fName.c_str(); }
reed@google.comc117cba2013-06-03 16:54:10 +000022
mtkleina1ebeb22015-10-01 09:43:39 -070023 void onDraw(int loops, SkCanvas*) override;
reed@google.comc117cba2013-06-03 16:54:10 +000024
25private:
mtklein9ff378b2015-04-09 14:05:17 -070026 int fN;
27 SkAutoTMalloc<T> fBuffer;
28 SkString fName;
reed@google.comc117cba2013-06-03 16:54:10 +000029};
30
mtkleina1ebeb22015-10-01 09:43:39 -070031template <> void MemsetBench<uint32_t, false>::onDraw(int loops, SkCanvas*) {
mtklein9ff378b2015-04-09 14:05:17 -070032 for (int i = 0; i < 1000*loops; i++) {
33 sk_memset32(fBuffer.get(), 0xFACEB004, fN);
reed@google.comc117cba2013-06-03 16:54:10 +000034 }
mtklein9ff378b2015-04-09 14:05:17 -070035}
reed@google.comc117cba2013-06-03 16:54:10 +000036
mtkleina1ebeb22015-10-01 09:43:39 -070037template <> void MemsetBench<uint16_t, false>::onDraw(int loops, SkCanvas*) {
mtklein9ff378b2015-04-09 14:05:17 -070038 for (int i = 0; i < 1000*loops; i++) {
39 sk_memset16(fBuffer.get(), 0x4973, fN);
reed@google.comc117cba2013-06-03 16:54:10 +000040 }
mtklein9ff378b2015-04-09 14:05:17 -070041}
reed@google.comc117cba2013-06-03 16:54:10 +000042
mtklein9ff378b2015-04-09 14:05:17 -070043template <typename T>
44static void memsetT(T* dst, T val, int n) {
45 for (int i = 0; i < n; i++) { dst[i] = val; }
46}
reed@google.comc117cba2013-06-03 16:54:10 +000047
mtkleina1ebeb22015-10-01 09:43:39 -070048template <> void MemsetBench<uint32_t, true>::onDraw(int loops, SkCanvas*) {
mtklein9ff378b2015-04-09 14:05:17 -070049 for (int i = 0; i < 1000*loops; i++) {
50 memsetT<uint32_t>(fBuffer.get(), 0xFACEB004, fN);
51 }
52}
53
mtkleina1ebeb22015-10-01 09:43:39 -070054template <> void MemsetBench<uint16_t, true>::onDraw(int loops, SkCanvas*) {
mtklein9ff378b2015-04-09 14:05:17 -070055 for (int i = 0; i < 1000*loops; i++) {
56 memsetT<uint16_t>(fBuffer.get(), 0x4973, fN);
57 }
58}
59
60DEF_BENCH(return (new MemsetBench<uint32_t, true>(1)));
61DEF_BENCH(return (new MemsetBench<uint32_t, false>(1)));
62DEF_BENCH(return (new MemsetBench<uint32_t, true>(10)));
63DEF_BENCH(return (new MemsetBench<uint32_t, false>(10)));
64DEF_BENCH(return (new MemsetBench<uint32_t, true>(100)));
65DEF_BENCH(return (new MemsetBench<uint32_t, false>(100)));
66DEF_BENCH(return (new MemsetBench<uint32_t, true>(1000)));
67DEF_BENCH(return (new MemsetBench<uint32_t, false>(1000)));
68DEF_BENCH(return (new MemsetBench<uint32_t, true>(10000)));
69DEF_BENCH(return (new MemsetBench<uint32_t, false>(10000)));
70DEF_BENCH(return (new MemsetBench<uint32_t, true>(100000)));
71DEF_BENCH(return (new MemsetBench<uint32_t, false>(100000)));
72
73DEF_BENCH(return (new MemsetBench<uint16_t, true>(1)));
74DEF_BENCH(return (new MemsetBench<uint16_t, false>(1)));
75DEF_BENCH(return (new MemsetBench<uint16_t, true>(10)));
76DEF_BENCH(return (new MemsetBench<uint16_t, false>(10)));
77DEF_BENCH(return (new MemsetBench<uint16_t, true>(100)));
78DEF_BENCH(return (new MemsetBench<uint16_t, false>(100)));
79DEF_BENCH(return (new MemsetBench<uint16_t, true>(1000)));
80DEF_BENCH(return (new MemsetBench<uint16_t, false>(1000)));
81DEF_BENCH(return (new MemsetBench<uint16_t, true>(10000)));
82DEF_BENCH(return (new MemsetBench<uint16_t, false>(10000)));
83DEF_BENCH(return (new MemsetBench<uint16_t, true>(100000)));
84DEF_BENCH(return (new MemsetBench<uint16_t, false>(100000)));