Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: bench/MemcpyBench.cpp

Issue 1256763003: Remove sk_memcpy32 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkUtils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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
8 #include "Benchmark.h"
9 #include "SkRandom.h"
10 #include "SkTemplates.h"
11 #include "SkUtils.h"
12
13 template <typename Memcpy32>
14 class Memcpy32Bench : public Benchmark {
15 public:
16 explicit Memcpy32Bench(int count, Memcpy32 memcpy32, const char* name)
17 : fCount(count)
18 , fMemcpy32(memcpy32)
19 , fName(SkStringPrintf("%s_%d", name, count)) {}
20
21 const char* onGetName() override {
22 return fName.c_str();
23 }
24
25 bool isSuitableFor(Backend backend) override {
26 return backend == kNonRendering_Backend;
27 }
28
29 void onPreDraw() override {
30 fDst.reset(fCount);
31 fSrc.reset(fCount);
32
33 SkRandom rand;
34 for (int i = 0; i < fCount; i++) {
35 fSrc[i] = rand.nextU();
36 }
37 }
38
39 void onDraw(const int loops, SkCanvas*) override {
40 for (int i = 0; i < loops; i++) {
41 fMemcpy32(fDst, fSrc, fCount);
42 }
43 }
44
45 private:
46 SkAutoTMalloc<uint32_t> fDst, fSrc;
47
48 int fCount;
49 Memcpy32 fMemcpy32;
50 const SkString fName;
51 };
52
53 template <typename Memcpy32>
54 static Memcpy32Bench<Memcpy32>* Bench(int count, Memcpy32 memcpy32, const char* name) {
55 return new Memcpy32Bench<Memcpy32>(count, memcpy32, name);
56 }
57 #define BENCH(memcpy32, count) DEF_BENCH(return Bench(count, memcpy32, #memcpy32 ); )
58
59
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);
63 }
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)
69
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)
76
77 #undef BENCH
OLDNEW
« no previous file with comments | « no previous file | include/core/SkUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698