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

Side by Side Diff: bench/PMFloatBench.cpp

Issue 1308903003: Templatize SkPMFloat to support both 1 and 255 biases. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pump the loops for Android Created 5 years, 3 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 | src/core/SkPMFloat.h » ('j') | src/effects/SkColorMatrixFilter.cpp » ('J')
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 "SkPMFloat.h" 9 #include "SkPMFloat.h"
10 10
11 // Used to prevent the compiler from optimizing away the whole loop. 11 // Used to prevent the compiler from optimizing away the whole loop.
12 volatile uint32_t blackhole = 0; 12 volatile uint32_t blackhole = 0;
13 13
14 // Not a great random number generator, but it's very fast. 14 // Not a great random number generator, but it's very fast.
15 // The code we're measuring is quite fast, so low overhead is essential. 15 // The code we're measuring is quite fast, so low overhead is essential.
16 static uint32_t lcg_rand(uint32_t* seed) { 16 static uint32_t lcg_rand(uint32_t* seed) {
17 *seed *= 1664525; 17 *seed *= 1664525;
18 *seed += 1013904223; 18 *seed += 1013904223;
19 return *seed; 19 return *seed;
20 } 20 }
21 21
22 // I'm having better luck getting these to constant-propagate away as template p arameters. 22 template <int kBias>
23 struct PMFloatRoundtripBench : public Benchmark { 23 struct PMFloatRoundtripBench : public Benchmark {
24 PMFloatRoundtripBench() {} 24 SkString fName;
25 PMFloatRoundtripBench() {
26 fName.appendf("SkPMFloat<%d>_roundtrip", kBias);
27 }
25 28
26 const char* onGetName() override { return "SkPMFloat_roundtrip"; } 29 const char* onGetName() override { return fName.c_str(); }
27 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 30 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
28 31
29 void onDraw(const int loops, SkCanvas* canvas) override { 32 void onDraw(const int loops, SkCanvas* canvas) override {
30 // Unlike blackhole, junk can and probably will be a register. 33 // Unlike blackhole, junk can and probably will be a register.
31 uint32_t junk = 0; 34 uint32_t junk = 0;
32 uint32_t seed = 0; 35 uint32_t seed = 0;
33 for (int i = 0; i < loops; i++) { 36 for (int i = 0; i < 1000*loops; i++) {
34 SkPMColor color; 37 SkPMColor color;
35 #ifdef SK_DEBUG 38 #ifdef SK_DEBUG
36 // Our SkASSERTs will remind us that it's technically required that we premultiply. 39 // Our SkASSERTs will remind us that it's technically required that we premultiply.
37 color = SkPreMultiplyColor(lcg_rand(&seed)); 40 color = SkPreMultiplyColor(lcg_rand(&seed));
38 #else 41 #else
39 // But it's a lot faster not to, and this code won't really mind the non-PM colors. 42 // But it's a lot faster not to, and this code won't really mind the non-PM colors.
40 color = lcg_rand(&seed); 43 color = lcg_rand(&seed);
41 #endif 44 #endif
42 45
43 auto f = SkPMFloat::FromPMColor(color); 46 auto f = SkPMFloat<kBias>::FromPMColor(color);
44 SkPMColor back = f.round(); 47 SkPMColor back = f.round();
45 junk ^= back; 48 junk ^= back;
46 } 49 }
47 blackhole ^= junk; 50 blackhole ^= junk;
48 } 51 }
49 }; 52 };
50 DEF_BENCH(return new PMFloatRoundtripBench;) 53 DEF_BENCH(return new PMFloatRoundtripBench<1>;)
54 DEF_BENCH(return new PMFloatRoundtripBench<255>;)
51 55
52 struct PMFloatGradientBench : public Benchmark { 56 struct PMFloatGradientBench : public Benchmark {
53 const char* onGetName() override { return "PMFloat_gradient"; } 57 const char* onGetName() override { return "PMFloat_gradient"; }
54 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; } 58 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
55 59
56 SkPMColor fDevice[100]; 60 SkPMColor fDevice[100];
57 void onDraw(const int loops, SkCanvas*) override { 61 void onDraw(const int loops, SkCanvas*) override {
58 Sk4f c0 = SkPMFloat::FromARGB(1, 1, 0, 0), 62 Sk4f c0 = SkPMFloat<1>::FromARGB(1, 1, 0, 0),
59 c1 = SkPMFloat::FromARGB(1, 0, 0, 1), 63 c1 = SkPMFloat<1>::FromARGB(1, 0, 0, 1),
60 dc = c1 - c0, 64 dc = c1 - c0,
61 fx(0.1f), 65 fx(0.1f),
62 dx(0.002f), 66 dx(0.002f),
63 dcdx(dc*dx), 67 dcdx(dc*dx),
64 dcdx4(dcdx+dcdx+dcdx+dcdx); 68 dcdx4(dcdx+dcdx+dcdx+dcdx);
65 69
66 for (int n = 0; n < loops; n++) { 70 for (int n = 0; n < loops; n++) {
67 Sk4f a = c0 + dc*fx, 71 Sk4f a = c0 + dc*fx,
68 b = a + dcdx, 72 b = a + dcdx,
69 c = b + dcdx, 73 c = b + dcdx,
70 d = c + dcdx; 74 d = c + dcdx;
71 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) { 75 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) {
72 fDevice[i+0] = SkPMFloat(a).round(); 76 fDevice[i+0] = SkPMFloat<1>(a).round();
73 fDevice[i+1] = SkPMFloat(b).round(); 77 fDevice[i+1] = SkPMFloat<1>(b).round();
74 fDevice[i+2] = SkPMFloat(c).round(); 78 fDevice[i+2] = SkPMFloat<1>(c).round();
75 fDevice[i+3] = SkPMFloat(d).round(); 79 fDevice[i+3] = SkPMFloat<1>(d).round();
76 a = a + dcdx4; 80 a = a + dcdx4;
77 b = b + dcdx4; 81 b = b + dcdx4;
78 c = c + dcdx4; 82 c = c + dcdx4;
79 d = d + dcdx4; 83 d = d + dcdx4;
80 } 84 }
81 } 85 }
82 } 86 }
83 }; 87 };
84 88
85 DEF_BENCH(return new PMFloatGradientBench;) 89 DEF_BENCH(return new PMFloatGradientBench;)
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | src/effects/SkColorMatrixFilter.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698