2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkTemplates.h"
13 template <typename Memcpy32>
14 class Memcpy32Bench : public Benchmark {
16 explicit Memcpy32Bench(int count, Memcpy32 memcpy32, const char* name)
19 , fName(SkStringPrintf("%s_%d", name, count)) {}
21 virtual const char* onGetName() SK_OVERRIDE {
25 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
26 return backend == kNonRendering_Backend;
29 virtual void onPreDraw() SK_OVERRIDE {
34 for (int i = 0; i < fCount; i++) {
35 fSrc[i] = rand.nextU();
39 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
40 for (int i = 0; i < loops; i++) {
41 fMemcpy32(fDst, fSrc, fCount);
46 SkAutoTMalloc<uint32_t> fDst, fSrc;
53 template <typename Memcpy32>
54 static Memcpy32Bench<Memcpy32>* Bench(int count, Memcpy32 memcpy32, const char* name) {
55 return new Memcpy32Bench<Memcpy32>(count, memcpy32, name);
57 #define BENCH(memcpy32, count) DEF_BENCH(return Bench(count, memcpy32, #memcpy32); )
60 // Let the libc developers do what they think is best.
61 static void memcpy32_memcpy(uint32_t* dst, const uint32_t* src, int count) {
62 memcpy(dst, src, sizeof(uint32_t) * count);
64 BENCH(memcpy32_memcpy, 10)
65 BENCH(memcpy32_memcpy, 100)
66 BENCH(memcpy32_memcpy, 1000)
67 BENCH(memcpy32_memcpy, 10000)
68 BENCH(memcpy32_memcpy, 100000)
70 // Test our chosen best, from SkUtils.h
71 BENCH(sk_memcpy32, 10)
72 BENCH(sk_memcpy32, 100)
73 BENCH(sk_memcpy32, 1000)
74 BENCH(sk_memcpy32, 10000)
75 BENCH(sk_memcpy32, 100000)