1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "bench/Benchmark.h" 9cb93a386Sopenharmony_ci#include "include/private/SkTemplates.h" 10cb93a386Sopenharmony_ci#include "src/core/SkOpts.h" 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_citemplate <typename T> 13cb93a386Sopenharmony_ciclass MemsetBench : public Benchmark { 14cb93a386Sopenharmony_cipublic: 15cb93a386Sopenharmony_ci explicit MemsetBench(size_t bytes) 16cb93a386Sopenharmony_ci : fN(bytes / sizeof(T)) 17cb93a386Sopenharmony_ci , fBuffer(fN) 18cb93a386Sopenharmony_ci , fName(SkStringPrintf("memset%zu_%zu", sizeof(T)*8, bytes)) {} 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ci bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } 21cb93a386Sopenharmony_ci const char* onGetName() override { return fName.c_str(); } 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci void onDraw(int loops, SkCanvas*) override; 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ciprivate: 26cb93a386Sopenharmony_ci int fN; 27cb93a386Sopenharmony_ci SkAutoTMalloc<T> fBuffer; 28cb93a386Sopenharmony_ci SkString fName; 29cb93a386Sopenharmony_ci}; 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_citemplate <> void MemsetBench<uint64_t>::onDraw(int loops, SkCanvas*) { 32cb93a386Sopenharmony_ci for (int i = 0; i < 1000*loops; i++) { 33cb93a386Sopenharmony_ci sk_memset64(fBuffer.get(), 0xFACEFACEFACEFACE, fN); 34cb93a386Sopenharmony_ci } 35cb93a386Sopenharmony_ci} 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_citemplate <> void MemsetBench<uint32_t>::onDraw(int loops, SkCanvas*) { 38cb93a386Sopenharmony_ci for (int i = 0; i < 1000*loops; i++) { 39cb93a386Sopenharmony_ci sk_memset32(fBuffer.get(), 0xFACEB004, fN); 40cb93a386Sopenharmony_ci } 41cb93a386Sopenharmony_ci} 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_citemplate <> void MemsetBench<uint16_t>::onDraw(int loops, SkCanvas*) { 44cb93a386Sopenharmony_ci for (int i = 0; i < 1000*loops; i++) { 45cb93a386Sopenharmony_ci sk_memset16(fBuffer.get(), 0x4973, fN); 46cb93a386Sopenharmony_ci } 47cb93a386Sopenharmony_ci} 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(16))); 50cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(64))); 51cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(256))); 52cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(512))); 53cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(768))); 54cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(1024))); 55cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(2048))); 56cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(4096))); 57cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint64_t>(65536))); 58cb93a386Sopenharmony_ci 59cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(16))); 60cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(64))); 61cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(256))); 62cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(512))); 63cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(768))); 64cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(1024))); 65cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(2048))); 66cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(4096))); 67cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint32_t>(65536))); 68cb93a386Sopenharmony_ci 69cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(16))); 70cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(64))); 71cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(256))); 72cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(512))); 73cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(768))); 74cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(1024))); 75cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(2048))); 76cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(4096))); 77cb93a386Sopenharmony_ciDEF_BENCH(return (new MemsetBench<uint16_t>(65536))); 78