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

Side by Side Diff: bench/GrOrderedSetBench.cpp

Issue 806653007: Fix up all the easy virtual ... SK_OVERRIDE cases. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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 | « bench/GrMemoryPoolBench.cpp ('k') | bench/HairlinePathBench.cpp » ('j') | 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 "SkRandom.h" 10 #include "SkRandom.h"
11 #include "SkString.h" 11 #include "SkString.h"
12 #if SK_SUPPORT_GPU 12 #if SK_SUPPORT_GPU
13 #include "GrOrderedSet.h" 13 #include "GrOrderedSet.h"
14 14
15 static const int NUM_ELEMENTS = 1000; 15 static const int NUM_ELEMENTS = 1000;
16 16
17 // Time how long it takes to build a set 17 // Time how long it takes to build a set
18 class GrOrderedSetBuildBench : public Benchmark { 18 class GrOrderedSetBuildBench : public Benchmark {
19 public: 19 public:
20 GrOrderedSetBuildBench() { 20 GrOrderedSetBuildBench() {
21 fName.append("ordered_set_build"); 21 fName.append("ordered_set_build");
22 } 22 }
23 23
24 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 24 bool isSuitableFor(Backend backend) SK_OVERRIDE {
25 return kNonRendering_Backend == backend; 25 return kNonRendering_Backend == backend;
26 } 26 }
27 27
28 virtual ~GrOrderedSetBuildBench() {} 28 virtual ~GrOrderedSetBuildBench() {}
29 29
30 protected: 30 protected:
31 virtual const char* onGetName() SK_OVERRIDE { 31 const char* onGetName() SK_OVERRIDE {
32 return fName.c_str(); 32 return fName.c_str();
33 } 33 }
34 34
35 virtual void onPreDraw() SK_OVERRIDE { 35 void onPreDraw() SK_OVERRIDE {
36 SkRandom rand; 36 SkRandom rand;
37 for (int j = 0; j < NUM_ELEMENTS; ++j) { 37 for (int j = 0; j < NUM_ELEMENTS; ++j) {
38 fData[j] = rand.nextU() % NUM_ELEMENTS; 38 fData[j] = rand.nextU() % NUM_ELEMENTS;
39 } 39 }
40 } 40 }
41 41
42 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 42 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
43 for (int i = 0; i < loops; ++i) { 43 for (int i = 0; i < loops; ++i) {
44 GrOrderedSet<int> set; 44 GrOrderedSet<int> set;
45 for (int j = 0; j < NUM_ELEMENTS; ++j) { 45 for (int j = 0; j < NUM_ELEMENTS; ++j) {
46 set.insert(fData[j]); 46 set.insert(fData[j]);
47 } 47 }
48 set.reset(); 48 set.reset();
49 } 49 }
50 } 50 }
51 51
52 private: 52 private:
53 SkString fName; 53 SkString fName;
54 int fData[NUM_ELEMENTS]; 54 int fData[NUM_ELEMENTS];
55 typedef Benchmark INHERITED; 55 typedef Benchmark INHERITED;
56 }; 56 };
57 57
58 // Time how long it takes to find elements in a set 58 // Time how long it takes to find elements in a set
59 class GrOrderedSetFindBench : public Benchmark { 59 class GrOrderedSetFindBench : public Benchmark {
60 public: 60 public:
61 GrOrderedSetFindBench() { 61 GrOrderedSetFindBench() {
62 fName.append("ordered_set_find"); 62 fName.append("ordered_set_find");
63 } 63 }
64 64
65 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 65 bool isSuitableFor(Backend backend) SK_OVERRIDE {
66 return kNonRendering_Backend == backend; 66 return kNonRendering_Backend == backend;
67 } 67 }
68 68
69 virtual ~GrOrderedSetFindBench() {} 69 virtual ~GrOrderedSetFindBench() {}
70 70
71 protected: 71 protected:
72 virtual const char* onGetName() SK_OVERRIDE { 72 const char* onGetName() SK_OVERRIDE {
73 return fName.c_str(); 73 return fName.c_str();
74 } 74 }
75 75
76 virtual void onPreDraw() SK_OVERRIDE { 76 void onPreDraw() SK_OVERRIDE {
77 SkRandom rand; 77 SkRandom rand;
78 for (int j = 0; j < NUM_ELEMENTS; ++j) { 78 for (int j = 0; j < NUM_ELEMENTS; ++j) {
79 fData[j] = rand.nextU() % 1500; 79 fData[j] = rand.nextU() % 1500;
80 fSet.insert(rand.nextU() % NUM_ELEMENTS); 80 fSet.insert(rand.nextU() % NUM_ELEMENTS);
81 } 81 }
82 } 82 }
83 83
84 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 84 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
85 for (int i = 0; i < loops; ++i) { 85 for (int i = 0; i < loops; ++i) {
86 for (int j = 0; j < NUM_ELEMENTS; ++j) { 86 for (int j = 0; j < NUM_ELEMENTS; ++j) {
87 fSet.find(fData[j]); 87 fSet.find(fData[j]);
88 } 88 }
89 } 89 }
90 } 90 }
91 91
92 private: 92 private:
93 SkString fName; 93 SkString fName;
94 int fData[NUM_ELEMENTS]; 94 int fData[NUM_ELEMENTS];
95 GrOrderedSet<int> fSet; 95 GrOrderedSet<int> fSet;
96 typedef Benchmark INHERITED; 96 typedef Benchmark INHERITED;
97 }; 97 };
98 98
99 // Time how long it takes to iterate over and remove all elements from set 99 // Time how long it takes to iterate over and remove all elements from set
100 class GrOrderedSetRemoveBench : public Benchmark { 100 class GrOrderedSetRemoveBench : public Benchmark {
101 public: 101 public:
102 GrOrderedSetRemoveBench() { 102 GrOrderedSetRemoveBench() {
103 fName.append("ordered_set_remove"); 103 fName.append("ordered_set_remove");
104 } 104 }
105 105
106 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 106 bool isSuitableFor(Backend backend) SK_OVERRIDE {
107 return kNonRendering_Backend == backend; 107 return kNonRendering_Backend == backend;
108 } 108 }
109 109
110 virtual ~GrOrderedSetRemoveBench() {} 110 virtual ~GrOrderedSetRemoveBench() {}
111 111
112 protected: 112 protected:
113 virtual const char* onGetName() SK_OVERRIDE { 113 const char* onGetName() SK_OVERRIDE {
114 return fName.c_str(); 114 return fName.c_str();
115 } 115 }
116 116
117 virtual void onPreDraw() SK_OVERRIDE { 117 void onPreDraw() SK_OVERRIDE {
118 SkRandom rand; 118 SkRandom rand;
119 for (int j = 0; j < NUM_ELEMENTS; ++j) { 119 for (int j = 0; j < NUM_ELEMENTS; ++j) {
120 fSet.insert(rand.nextU() % NUM_ELEMENTS); 120 fSet.insert(rand.nextU() % NUM_ELEMENTS);
121 } 121 }
122 } 122 }
123 123
124 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 124 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
125 typedef GrOrderedSet<int>::Iter SetIter; 125 typedef GrOrderedSet<int>::Iter SetIter;
126 for (int i = 0; i < loops; ++i) { 126 for (int i = 0; i < loops; ++i) {
127 GrOrderedSet<int> testSet; 127 GrOrderedSet<int> testSet;
128 for (SetIter s = fSet.begin(); fSet.end() != s; ++s) { 128 for (SetIter s = fSet.begin(); fSet.end() != s; ++s) {
129 testSet.insert(*s); 129 testSet.insert(*s);
130 } 130 }
131 for (int j = 0; j < NUM_ELEMENTS; ++j) { 131 for (int j = 0; j < NUM_ELEMENTS; ++j) {
132 testSet.remove(testSet.find(j)); 132 testSet.remove(testSet.find(j));
133 } 133 }
134 } 134 }
135 } 135 }
136 136
137 private: 137 private:
138 SkString fName; 138 SkString fName;
139 GrOrderedSet<int> fSet; 139 GrOrderedSet<int> fSet;
140 typedef Benchmark INHERITED; 140 typedef Benchmark INHERITED;
141 }; 141 };
142 142
143 /////////////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////////////
144 144
145 DEF_BENCH(return SkNEW_ARGS(GrOrderedSetBuildBench, ());) 145 DEF_BENCH(return SkNEW_ARGS(GrOrderedSetBuildBench, ());)
146 DEF_BENCH(return SkNEW_ARGS(GrOrderedSetFindBench, ());) 146 DEF_BENCH(return SkNEW_ARGS(GrOrderedSetFindBench, ());)
147 DEF_BENCH(return SkNEW_ARGS(GrOrderedSetRemoveBench, ());) 147 DEF_BENCH(return SkNEW_ARGS(GrOrderedSetRemoveBench, ());)
148 #endif 148 #endif
OLDNEW
« no previous file with comments | « bench/GrMemoryPoolBench.cpp ('k') | bench/HairlinePathBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698