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

Side by Side Diff: bench/StackBench.cpp

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

Powered by Google App Engine
This is Rietveld 408576698