blob: d1682bdd70c459b2219a81b161b69faed27cb347 [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
mtklein9ff378b2015-04-09 14:05:17 -07009#include "SkTemplates.h"
tfarinaf168b862014-06-19 12:32:29 -070010#include "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
mtklein9ff378b2015-04-09 14:05:17 -070023 void onDraw(const 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
mtklein9ff378b2015-04-09 14:05:17 -070031template <> void MemsetBench<uint32_t, false>::onDraw(const int loops, SkCanvas*) {
32 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
mtklein9ff378b2015-04-09 14:05:17 -070037template <> void MemsetBench<uint16_t, false>::onDraw(const int loops, SkCanvas*) {
38 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
mtklein9ff378b2015-04-09 14:05:17 -070048template <> void MemsetBench<uint32_t, true>::onDraw(const int loops, SkCanvas*) {
49 for (int i = 0; i < 1000*loops; i++) {
50 memsetT<uint32_t>(fBuffer.get(), 0xFACEB004, fN);
51 }
52}
53
54template <> void MemsetBench<uint16_t, true>::onDraw(const int loops, SkCanvas*) {
55 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)));