OLD | NEW |
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 bool isSuitableFor(Backend backend) SK_OVERRIDE { | 24 bool isSuitableFor(Backend backend) 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 const char* onGetName() SK_OVERRIDE { | 31 const char* onGetName() override { |
32 return fName.c_str(); | 32 return fName.c_str(); |
33 } | 33 } |
34 | 34 |
35 void onPreDraw() SK_OVERRIDE { | 35 void onPreDraw() 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 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 42 void onDraw(const int loops, SkCanvas* canvas) 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 bool isSuitableFor(Backend backend) SK_OVERRIDE { | 65 bool isSuitableFor(Backend backend) 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 const char* onGetName() SK_OVERRIDE { | 72 const char* onGetName() override { |
73 return fName.c_str(); | 73 return fName.c_str(); |
74 } | 74 } |
75 | 75 |
76 void onPreDraw() SK_OVERRIDE { | 76 void onPreDraw() 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 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 84 void onDraw(const int loops, SkCanvas* canvas) 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 bool isSuitableFor(Backend backend) SK_OVERRIDE { | 106 bool isSuitableFor(Backend backend) 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 const char* onGetName() SK_OVERRIDE { | 113 const char* onGetName() override { |
114 return fName.c_str(); | 114 return fName.c_str(); |
115 } | 115 } |
116 | 116 |
117 void onPreDraw() SK_OVERRIDE { | 117 void onPreDraw() 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 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 124 void onDraw(const int loops, SkCanvas* canvas) 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 |
OLD | NEW |