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

Side by Side Diff: bench/StackBench.cpp

Issue 129443002: Revert of For comparison, add std::vector. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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 "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 10
11 #include "SkChunkAlloc.h" 11 #include "SkChunkAlloc.h"
12 #include "SkDeque.h" 12 #include "SkDeque.h"
13 #include "SkTArray.h" 13 #include "SkTArray.h"
14 #include "SkTDArray.h" 14 #include "SkTDArray.h"
15 #include <vector>
16 15
17 // This file has several benchmarks using various data structures to do stack-li ke things: 16 // This file has several benchmarks using various data structures to do stack-li ke things:
18 // - push 17 // - push
19 // - push, immediately pop 18 // - push, immediately pop
20 // - push many, pop all of them 19 // - push many, pop all of them
21 // - serial access 20 // - serial access
22 // - random access 21 // - random access
23 // When a data structure doesn't suppport an operation efficiently, we leave tha t combination out. 22 // When a data structure doesn't suppport an operation efficiently, we leave tha t combination out.
24 // Where possible we hint to the data structure to allocate in 4K pages. 23 // Where possible we hint to the data structure to allocate in 4K pages.
25 // 24 //
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 BENCH(TDArray_Serial) { 71 BENCH(TDArray_Serial) {
73 SkTDArray<int> s; 72 SkTDArray<int> s;
74 for (int i = 0; i < K; i++) s.push(i); 73 for (int i = 0; i < K; i++) s.push(i);
75 74
76 volatile int junk = 0; 75 volatile int junk = 0;
77 for (int j = 0; j < loops; j++) { 76 for (int j = 0; j < loops; j++) {
78 for (int i = 0; i < s.count(); i++) junk += s[i]; 77 for (int i = 0; i < s.count(); i++) junk += s[i];
79 } 78 }
80 } 79 }
81 80
82 BENCH(vector_Serial) {
83 std::vector<int> s;
84 for (int i = 0; i < K; i++) s.push_back(i);
85
86 volatile int junk = 0;
87 for (int j = 0; j < loops; j++) {
88 for (size_t i = 0; i < s.size(); i++) junk += s[i];
89 }
90 }
91
92 // Add K items, then randomly access them many times. 81 // Add K items, then randomly access them many times.
93 82
94 BENCH(TArray_RandomAccess) { 83 BENCH(TArray_RandomAccess) {
95 SkTArray<int, true> s; 84 SkTArray<int, true> s;
96 for (int i = 0; i < K; i++) s.push_back(i); 85 for (int i = 0; i < K; i++) s.push_back(i);
97 86
98 SkRandom rand; 87 SkRandom rand;
99 volatile int junk = 0; 88 volatile int junk = 0;
100 for (int i = 0; i < K*loops; i++) { 89 for (int i = 0; i < K*loops; i++) {
101 junk += s[rand.nextULessThan(K)]; 90 junk += s[rand.nextULessThan(K)];
102 } 91 }
103 } 92 }
104 93
105 BENCH(TDArray_RandomAccess) { 94 BENCH(TDArray_RandomAccess) {
106 SkTDArray<int> s; 95 SkTDArray<int> s;
107 for (int i = 0; i < K; i++) s.push(i); 96 for (int i = 0; i < K; i++) s.push(i);
108 97
109 SkRandom rand; 98 SkRandom rand;
110 volatile int junk = 0; 99 volatile int junk = 0;
111 for (int i = 0; i < K*loops; i++) {
112 junk += s[rand.nextULessThan(K)];
113 }
114 }
115
116 BENCH(vector_RandomAccess) {
117 std::vector<int> s;
118 for (int i = 0; i < K; i++) s.push_back(i);
119
120 SkRandom rand;
121 volatile int junk = 0;
122 for (int i = 0; i < K*loops; i++) { 100 for (int i = 0; i < K*loops; i++) {
123 junk += s[rand.nextULessThan(K)]; 101 junk += s[rand.nextULessThan(K)];
124 } 102 }
125 } 103 }
126 104
127 // Push many times. 105 // Push many times.
128 106
129 BENCH(ChunkAlloc_Push) { 107 BENCH(ChunkAlloc_Push) {
130 SkChunkAlloc s(4096); 108 SkChunkAlloc s(4096);
131 for (int i = 0; i < K*loops; i++) s.allocThrow(sizeof(int)); 109 for (int i = 0; i < K*loops; i++) s.allocThrow(sizeof(int));
132 } 110 }
133 111
134 BENCH(Deque_Push) { 112 BENCH(Deque_Push) {
135 SkDeque s(sizeof(int), 1024); 113 SkDeque s(sizeof(int), 1024);
136 for (int i = 0; i < K*loops; i++) *(int*)s.push_back() = i; 114 for (int i = 0; i < K*loops; i++) *(int*)s.push_back() = i;
137 } 115 }
138 116
139 BENCH(TArray_Push) { 117 BENCH(TArray_Push) {
140 SkTArray<int, true> s; 118 SkTArray<int, true> s;
141 for (int i = 0; i < K*loops; i++) s.push_back(i); 119 for (int i = 0; i < K*loops; i++) s.push_back(i);
142 } 120 }
143 121
144 BENCH(TDArray_Push) { 122 BENCH(TDArray_Push) {
145 SkTDArray<int> s; 123 SkTDArray<int> s;
146 for (int i = 0; i < K*loops; i++) s.push(i); 124 for (int i = 0; i < K*loops; i++) s.push(i);
147 } 125 }
148 126
149 BENCH(vector_Push) {
150 std::vector<int> s;
151 for (int i = 0; i < K*loops; i++) s.push_back(i);
152 }
153
154 // Push then immediately pop many times. 127 // Push then immediately pop many times.
155 128
156 BENCH(ChunkAlloc_PushPop) { 129 BENCH(ChunkAlloc_PushPop) {
157 SkChunkAlloc s(4096); 130 SkChunkAlloc s(4096);
158 for (int i = 0; i < K*loops; i++) { 131 for (int i = 0; i < K*loops; i++) {
159 void* p = s.allocThrow(sizeof(int)); 132 void* p = s.allocThrow(sizeof(int));
160 s.unalloc(p); 133 s.unalloc(p);
161 } 134 }
162 } 135 }
163 136
(...skipping 14 matching lines...) Expand all
178 } 151 }
179 152
180 BENCH(TDArray_PushPop) { 153 BENCH(TDArray_PushPop) {
181 SkTDArray<int> s; 154 SkTDArray<int> s;
182 for (int i = 0; i < K*loops; i++) { 155 for (int i = 0; i < K*loops; i++) {
183 s.push(i); 156 s.push(i);
184 s.pop(); 157 s.pop();
185 } 158 }
186 } 159 }
187 160
188 BENCH(vector_PushPop) {
189 std::vector<int> s;
190 for (int i = 0; i < K*loops; i++) {
191 s.push_back(i);
192 s.pop_back();
193 }
194 }
195
196 // Push many items, then pop them all. 161 // Push many items, then pop them all.
197 162
198 BENCH(Deque_PushAllPopAll) { 163 BENCH(Deque_PushAllPopAll) {
199 SkDeque s(sizeof(int), 1024); 164 SkDeque s(sizeof(int), 1024);
200 for (int i = 0; i < K*loops; i++) *(int*)s.push_back() = i; 165 for (int i = 0; i < K*loops; i++) *(int*)s.push_back() = i;
201 for (int i = 0; i < K*loops; i++) s.pop_back(); 166 for (int i = 0; i < K*loops; i++) s.pop_back();
202 } 167 }
203 168
204 BENCH(TArray_PushAllPopAll) { 169 BENCH(TArray_PushAllPopAll) {
205 SkTArray<int, true> s; 170 SkTArray<int, true> s;
206 for (int i = 0; i < K*loops; i++) s.push_back(i); 171 for (int i = 0; i < K*loops; i++) s.push_back(i);
207 for (int i = 0; i < K*loops; i++) s.pop_back(); 172 for (int i = 0; i < K*loops; i++) s.pop_back();
208 } 173 }
209 174
210 BENCH(TDArray_PushAllPopAll) { 175 BENCH(TDArray_PushAllPopAll) {
211 SkTDArray<int> s; 176 SkTDArray<int> s;
212 for (int i = 0; i < K*loops; i++) s.push(i); 177 for (int i = 0; i < K*loops; i++) s.push(i);
213 for (int i = 0; i < K*loops; i++) s.pop(); 178 for (int i = 0; i < K*loops; i++) s.pop();
214 } 179 }
215
216 BENCH(vector_PushAllPopAll) {
217 std::vector<int> s;
218 for (int i = 0; i < K*loops; i++) s.push_back(i);
219 for (int i = 0; i < K*loops; i++) s.pop_back();
220 }
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