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

Side by Side Diff: bench/PictureNestingBench.cpp

Issue 784173004: PictureNestingBench: stay in ints. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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 2014 Google Inc. 2 * Copyright 2014 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
11 #include "SkNullCanvas.h" 11 #include "SkNullCanvas.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkPicture.h" 13 #include "SkPicture.h"
14 #include "SkPictureRecorder.h" 14 #include "SkPictureRecorder.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 16
17 #include <math.h>
18
19 class PictureNesting : public Benchmark { 17 class PictureNesting : public Benchmark {
20 public: 18 public:
21 PictureNesting(const char* name, int maxLevel, int maxPictureLevel) 19 PictureNesting(const char* name, int maxLevel, int maxPictureLevel)
22 : fMaxLevel(maxLevel) 20 : fMaxLevel(maxLevel)
23 , fMaxPictureLevel(maxPictureLevel) { 21 , fMaxPictureLevel(maxPictureLevel) {
24 fName.printf("picture_nesting_%s_%d", name, this->countPics()); 22 fName.printf("picture_nesting_%s_%d", name, this->countPics());
25 fPaint.setColor(SK_ColorRED); 23 fPaint.setColor(SK_ColorRED);
26 fPaint.setAntiAlias(true); 24 fPaint.setAntiAlias(true);
27 fPaint.setStyle(SkPaint::kStroke_Style); 25 fPaint.setStyle(SkPaint::kStroke_Style);
28 } 26 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 int fMaxLevel; 84 int fMaxLevel;
87 int fMaxPictureLevel; 85 int fMaxPictureLevel;
88 86
89 private: 87 private:
90 int countPics() const { 88 int countPics() const {
91 // Solve: pics from sierpinsky 89 // Solve: pics from sierpinsky
92 // f(m) = 1 + 3*f(m - 1) 90 // f(m) = 1 + 3*f(m - 1)
93 // f(0) = 0 91 // f(0) = 0
94 // via "recursive function to closed form" tricks 92 // via "recursive function to closed form" tricks
95 // f(m) = 1/2 (3^m - 1) 93 // f(m) = 1/2 (3^m - 1)
96 return static_cast<int>((pow(3.0, fMaxPictureLevel) - 1.0) / 2.0); 94 int pics = 1;
95 for (int i = 0; i < fMaxPictureLevel; i++) {
96 pics *= 3;
97 }
98 pics--;
99 pics /= 2;
100 return pics;
97 } 101 }
98 102
99 SkString fName; 103 SkString fName;
100 SkPaint fPaint; 104 SkPaint fPaint;
101 105
102 typedef Benchmark INHERITED; 106 typedef Benchmark INHERITED;
103 }; 107 };
104 108
105 class PictureNestingRecording : public PictureNesting { 109 class PictureNestingRecording : public PictureNesting {
106 public: 110 public:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 175
172 DEF_BENCH( return new PictureNestingPlayback(8, 0); ) 176 DEF_BENCH( return new PictureNestingPlayback(8, 0); )
173 DEF_BENCH( return new PictureNestingPlayback(8, 1); ) 177 DEF_BENCH( return new PictureNestingPlayback(8, 1); )
174 DEF_BENCH( return new PictureNestingPlayback(8, 2); ) 178 DEF_BENCH( return new PictureNestingPlayback(8, 2); )
175 DEF_BENCH( return new PictureNestingPlayback(8, 3); ) 179 DEF_BENCH( return new PictureNestingPlayback(8, 3); )
176 DEF_BENCH( return new PictureNestingPlayback(8, 4); ) 180 DEF_BENCH( return new PictureNestingPlayback(8, 4); )
177 DEF_BENCH( return new PictureNestingPlayback(8, 5); ) 181 DEF_BENCH( return new PictureNestingPlayback(8, 5); )
178 DEF_BENCH( return new PictureNestingPlayback(8, 6); ) 182 DEF_BENCH( return new PictureNestingPlayback(8, 6); )
179 DEF_BENCH( return new PictureNestingPlayback(8, 7); ) 183 DEF_BENCH( return new PictureNestingPlayback(8, 7); )
180 DEF_BENCH( return new PictureNestingPlayback(8, 8); ) 184 DEF_BENCH( return new PictureNestingPlayback(8, 8); )
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