skia2/bench/MemsetBench.cpp
Kevin Lubick 3a9a7991c4 Move sk_memset* from SkUtils to SkOpts
This is a (hopefully) more careful reland of parts of
https://skia-review.googlesource.com/c/skia/+/464876

Change-Id: I32dd6777a70d983d8a66a4bf9557cab6e3d7ebc2
Bug: skia:12584
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/467124
Reviewed-by: Greg Daniel <egdaniel@google.com>
2021-11-03 17:03:21 +00:00

78 lines
2.6 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/private/SkTemplates.h"
#include "src/core/SkOpts.h"
template <typename T>
class MemsetBench : public Benchmark {
public:
explicit MemsetBench(size_t bytes)
: fN(bytes / sizeof(T))
, fBuffer(fN)
, fName(SkStringPrintf("memset%zu_%zu", sizeof(T)*8, bytes)) {}
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
const char* onGetName() override { return fName.c_str(); }
void onDraw(int loops, SkCanvas*) override;
private:
int fN;
SkAutoTMalloc<T> fBuffer;
SkString fName;
};
template <> void MemsetBench<uint64_t>::onDraw(int loops, SkCanvas*) {
for (int i = 0; i < 1000*loops; i++) {
sk_memset64(fBuffer.get(), 0xFACEFACEFACEFACE, fN);
}
}
template <> void MemsetBench<uint32_t>::onDraw(int loops, SkCanvas*) {
for (int i = 0; i < 1000*loops; i++) {
sk_memset32(fBuffer.get(), 0xFACEB004, fN);
}
}
template <> void MemsetBench<uint16_t>::onDraw(int loops, SkCanvas*) {
for (int i = 0; i < 1000*loops; i++) {
sk_memset16(fBuffer.get(), 0x4973, fN);
}
}
DEF_BENCH(return (new MemsetBench<uint64_t>(16)));
DEF_BENCH(return (new MemsetBench<uint64_t>(64)));
DEF_BENCH(return (new MemsetBench<uint64_t>(256)));
DEF_BENCH(return (new MemsetBench<uint64_t>(512)));
DEF_BENCH(return (new MemsetBench<uint64_t>(768)));
DEF_BENCH(return (new MemsetBench<uint64_t>(1024)));
DEF_BENCH(return (new MemsetBench<uint64_t>(2048)));
DEF_BENCH(return (new MemsetBench<uint64_t>(4096)));
DEF_BENCH(return (new MemsetBench<uint64_t>(65536)));
DEF_BENCH(return (new MemsetBench<uint32_t>(16)));
DEF_BENCH(return (new MemsetBench<uint32_t>(64)));
DEF_BENCH(return (new MemsetBench<uint32_t>(256)));
DEF_BENCH(return (new MemsetBench<uint32_t>(512)));
DEF_BENCH(return (new MemsetBench<uint32_t>(768)));
DEF_BENCH(return (new MemsetBench<uint32_t>(1024)));
DEF_BENCH(return (new MemsetBench<uint32_t>(2048)));
DEF_BENCH(return (new MemsetBench<uint32_t>(4096)));
DEF_BENCH(return (new MemsetBench<uint32_t>(65536)));
DEF_BENCH(return (new MemsetBench<uint16_t>(16)));
DEF_BENCH(return (new MemsetBench<uint16_t>(64)));
DEF_BENCH(return (new MemsetBench<uint16_t>(256)));
DEF_BENCH(return (new MemsetBench<uint16_t>(512)));
DEF_BENCH(return (new MemsetBench<uint16_t>(768)));
DEF_BENCH(return (new MemsetBench<uint16_t>(1024)));
DEF_BENCH(return (new MemsetBench<uint16_t>(2048)));
DEF_BENCH(return (new MemsetBench<uint16_t>(4096)));
DEF_BENCH(return (new MemsetBench<uint16_t>(65536)));