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

Side by Side Diff: bench/Sk4fBench.cpp

Issue 1682793002: Slim down Sk4fRoundtrip benches. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkNx.h" 10 #include "SkNx.h"
11 11
12 // Used to prevent the compiler from optimizing away the whole loop. 12 // Writing into this array prevents the loops from being compiled away.
13 volatile uint64_t blackhole = 0; 13 static volatile float blackhole[4];
14
15 // Not a great random number generator, but it's very fast.
16 // The code we're measuring is quite fast, so low overhead is essential.
17 static uint64_t lcg_rand(uint64_t* seed) {
18 *seed *= 1664525;
19 *seed += 1013904223;
20 return *seed;
21 }
22 14
23 template <typename T> 15 template <typename T>
24 struct Sk4fRoundtripBench : public Benchmark { 16 struct Sk4fRoundtripBench : public Benchmark {
25 Sk4fRoundtripBench() {} 17 Sk4fRoundtripBench() {}
26 18
27 const char* onGetName() override { 19 const char* onGetName() override {
28 switch (sizeof(T)) { 20 switch (sizeof(T)) {
29 case 1: return "Sk4f_roundtrip_u8"; 21 case 1: return "Sk4f_roundtrip_u8";
30 case 2: return "Sk4f_roundtrip_u16"; 22 case 2: return "Sk4f_roundtrip_u16";
23 case 4: return "Sk4f_roundtrip_int";
31 } 24 }
32 SkASSERT(false); 25 SkASSERT(false);
33 return ""; 26 return "";
34 } 27 }
35 28
36 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 29 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
37 30
38 void onDraw(int loops, SkCanvas* canvas) override { 31 void onDraw(int loops, SkCanvas* canvas) override {
39 // Unlike blackhole, junk can and probably will be a register. 32 Sk4f fs(1,2,3,4);
40 uint64_t junk = 0; 33 while (loops --> 0) {
41 uint64_t seed = 0; 34 fs = SkNx_cast<float>(SkNx_cast<T>(fs));
42 for (int i = 0; i < loops; i++) {
43 uint64_t src = lcg_rand(&seed),
44 back;
45 auto f = SkNx_cast<float>(SkNx<4,T>::Load(&src));
46 SkNx_cast<T>(f).store(&back);
47 junk ^= back;
48 } 35 }
49 blackhole ^= junk; 36 fs.store((float*)blackhole);
50 } 37 }
51 }; 38 };
52 DEF_BENCH(return new Sk4fRoundtripBench<uint8_t>;) 39 DEF_BENCH(return new Sk4fRoundtripBench<uint8_t>;)
53 DEF_BENCH(return new Sk4fRoundtripBench<uint16_t>;) 40 DEF_BENCH(return new Sk4fRoundtripBench<uint16_t>;)
41 DEF_BENCH(return new Sk4fRoundtripBench<int>;)
54 42
55 struct Sk4fGradientBench : public Benchmark { 43 struct Sk4fGradientBench : public Benchmark {
56 const char* onGetName() override { return "Sk4f_gradient"; } 44 const char* onGetName() override { return "Sk4f_gradient"; }
57 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 45 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
58 46
59 SkPMColor fDevice[100]; 47 SkPMColor fDevice[100];
60 void onDraw(int loops, SkCanvas*) override { 48 void onDraw(int loops, SkCanvas*) override {
61 Sk4f c0(0,0,255,255), 49 Sk4f c0(0,0,255,255),
62 c1(255,0,0,255), 50 c1(255,0,0,255),
63 dc = c1 - c0, 51 dc = c1 - c0,
(...skipping 11 matching lines...) Expand all
75 Sk4f_ToBytes((uint8_t*)(fDevice+i), a, b, c, d); 63 Sk4f_ToBytes((uint8_t*)(fDevice+i), a, b, c, d);
76 a = a + dcdx4; 64 a = a + dcdx4;
77 b = b + dcdx4; 65 b = b + dcdx4;
78 c = c + dcdx4; 66 c = c + dcdx4;
79 d = d + dcdx4; 67 d = d + dcdx4;
80 } 68 }
81 } 69 }
82 } 70 }
83 }; 71 };
84 DEF_BENCH(return new Sk4fGradientBench;) 72 DEF_BENCH(return new Sk4fGradientBench;)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698