proxygen
FBVectorBenchmark.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //
18 // Author: andrei.alexandrescu@fb.com
19 
20 #include <deque>
21 #include <list>
22 #include <memory>
23 #include <string>
24 
25 #include <boost/random.hpp>
26 
27 #include <folly/FBVector.h>
28 #include <folly/Traits.h>
31 #include <folly/small_vector.h>
33 
34 using namespace std;
35 using namespace folly;
36 using namespace folly::test::detail;
37 
38 using IntVector = vector<int>;
40 using IntList = list<int>;
41 using IntDeque = deque<int>;
43 
44 using StringVector = vector<std::string>;
46 using StringList = list<std::string>;
47 using StringDeque = deque<std::string>;
49 
50 using FBStringVector = vector<folly::fbstring>;
52 
53 #define VECTOR IntVector
54 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
55 #undef VECTOR
56 #define VECTOR IntFBVector
57 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
58 #undef VECTOR
59 #define VECTOR IntSmallVector
60 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
61 #undef VECTOR
62 #define VECTOR IntList
63 #define SKIP_RESERVE
64 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
65 #undef SKIP_RESERVE
66 #undef VECTOR
67 #define VECTOR IntDeque
68 #define SKIP_RESERVE
69 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
70 #undef SKIP_RESERVE
71 #undef VECTOR
72 
73 #define VECTOR StringVector
74 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
75 #undef VECTOR
76 #define VECTOR StringFBVector
77 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
78 #undef VECTOR
79 #define VECTOR StringSmallVector
80 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
81 #undef VECTOR
82 #define VECTOR StringList
83 #define SKIP_RESERVE
84 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
85 #undef SKIP_RESERVE
86 #undef VECTOR
87 #define VECTOR StringDeque
88 #define SKIP_RESERVE
89 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
90 #undef SKIP_RESERVE
91 #undef VECTOR
92 
93 #define VECTOR FBStringVector
94 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
95 #undef VECTOR
96 #define VECTOR FBStringFBVector
97 #include <folly/test/FBVectorBenchmarks.cpp.h> // nolint
98 #undef VECTOR
99 
100 int main(int argc, char** argv) {
101  gflags::ParseCommandLineFlags(&argc, &argv, true);
102  gflags::SetCommandLineOptionWithMode(
103  "bm_max_iters", "1000000", gflags::SET_FLAG_IF_DEFAULT);
104  gflags::SetCommandLineOptionWithMode(
105  "bm_min_iters", "100000", gflags::SET_FLAG_IF_DEFAULT);
106  gflags::SetCommandLineOptionWithMode(
107  "bm_max_secs", "1", gflags::SET_FLAG_IF_DEFAULT);
108 
110  return 0;
111 }
112 
113 // clang-format off
114 /*
115 ============================================================================
116 buck-out/opt/gen/folly/test/fbvector_benchmark#gcc-5-glibc-2.23,private-headers/folly/test/FBVectorBenchmarks.cpp.hrelative time/iter iters/s
117 ============================================================================
118 BM_zzInitRNG_IntVector 1.05us 951.24K
119 BM_defaultCtor_IntVector 1.31ns 765.93M
120 BM_sizeCtor_IntVector(16) 19.33ns 51.73M
121 BM_sizeCtor_IntVector(128) 42.11ns 23.75M
122 BM_sizeCtor_IntVector(1024) 60.90ns 16.42M
123 BM_fillCtor_IntVector(16) 30.67ns 32.61M
124 BM_fillCtor_IntVector(128) 41.22ns 24.26M
125 BM_fillCtor_IntVector(1024) 133.70ns 7.48M
126 BM_reserve_IntVector(16) 40.27ns 24.83M
127 BM_reserve_IntVector(128) 40.20ns 24.88M
128 BM_reserve_IntVector(1024) 40.17ns 24.90M
129 BM_insertFront_IntVector(16) 7.90us 126.52K
130 BM_insertFront_IntVector(128) 8.12us 123.09K
131 BM_insertFront_IntVector(1024) 8.30us 120.46K
132 BM_insertFront_IntVector(10240) 10.14us 98.67K
133 BM_insertFront_IntVector(102400) 30.71us 32.56K
134 BM_insertFront_IntVector(1024000) 220.69us 4.53K
135 BM_pushBack_IntVector(16) 776.38ps 1.29G
136 BM_pushBack_IntVector(128) 775.89ps 1.29G
137 BM_pushBack_IntVector(1024) 742.50ps 1.35G
138 BM_pushBack_IntVector(10240) 787.75ps 1.27G
139 BM_pushBack_IntVector(102400) 714.07ps 1.40G
140 BM_pushBack_IntVector(1024000) 3.15ns 317.26M
141 BM_zzInitRNG_IntFBVector 1.17us 853.35K
142 BM_defaultCtor_IntFBVector 989.76ps 1.01G
143 BM_sizeCtor_IntFBVector(16) 27.19ns 36.78M
144 BM_sizeCtor_IntFBVector(128) 46.73ns 21.40M
145 BM_sizeCtor_IntFBVector(1024) 69.03ns 14.49M
146 BM_fillCtor_IntFBVector(16) 35.97ns 27.80M
147 BM_fillCtor_IntFBVector(128) 55.11ns 18.15M
148 BM_fillCtor_IntFBVector(1024) 147.89ns 6.76M
149 BM_reserve_IntFBVector(16) 54.18ns 18.46M
150 BM_reserve_IntFBVector(128) 54.24ns 18.44M
151 BM_reserve_IntFBVector(1024) 54.24ns 18.44M
152 BM_insertFront_IntFBVector(16) 8.41us 118.86K
153 BM_insertFront_IntFBVector(128) 8.45us 118.41K
154 BM_insertFront_IntFBVector(1024) 8.56us 116.80K
155 BM_insertFront_IntFBVector(10240) 10.72us 93.32K
156 BM_insertFront_IntFBVector(102400) 30.83us 32.43K
157 BM_insertFront_IntFBVector(1024000) 217.31us 4.60K
158 BM_pushBack_IntFBVector(16) 2.05ns 488.26M
159 BM_pushBack_IntFBVector(128) 1.99ns 503.65M
160 BM_pushBack_IntFBVector(1024) 2.16ns 462.50M
161 BM_pushBack_IntFBVector(10240) 2.13ns 468.48M
162 BM_pushBack_IntFBVector(102400) 1.93ns 517.23M
163 BM_pushBack_IntFBVector(1024000) 1.89ns 529.29M
164 BM_zzInitRNG_IntSmallVector 1.17us 855.04K
165 BM_defaultCtor_IntSmallVector 698.82ps 1.43G
166 BM_sizeCtor_IntSmallVector(16) 37.59ns 26.60M
167 BM_sizeCtor_IntSmallVector(128) 85.90ns 11.64M
168 BM_sizeCtor_IntSmallVector(1024) 401.37ns 2.49M
169 BM_fillCtor_IntSmallVector(16) 48.22ns 20.74M
170 BM_fillCtor_IntSmallVector(128) 99.99ns 10.00M
171 BM_fillCtor_IntSmallVector(1024) 458.71ns 2.18M
172 BM_reserve_IntSmallVector(16) 44.30ns 22.57M
173 BM_reserve_IntSmallVector(128) 44.29ns 22.58M
174 BM_reserve_IntSmallVector(1024) 45.15ns 22.15M
175 BM_insertFront_IntSmallVector(16) 8.40us 119.11K
176 BM_insertFront_IntSmallVector(128) 7.74us 129.25K
177 BM_insertFront_IntSmallVector(1024) 8.17us 122.47K
178 BM_insertFront_IntSmallVector(10240) 10.17us 98.34K
179 BM_insertFront_IntSmallVector(102400) 29.60us 33.79K
180 BM_insertFront_IntSmallVector(1024000) 208.82us 4.79K
181 BM_pushBack_IntSmallVector(16) 2.92ns 342.66M
182 BM_pushBack_IntSmallVector(128) 2.91ns 343.36M
183 BM_pushBack_IntSmallVector(1024) 2.76ns 362.74M
184 BM_pushBack_IntSmallVector(10240) 2.71ns 369.18M
185 BM_pushBack_IntSmallVector(102400) 3.04ns 329.36M
186 BM_pushBack_IntSmallVector(1024000) 4.90ns 204.21M
187 BM_zzInitRNG_IntList 1.04us 958.67K
188 BM_defaultCtor_IntList 911.25ps 1.10G
189 BM_sizeCtor_IntList(16) 264.10ns 3.79M
190 BM_sizeCtor_IntList(128) 2.08us 481.87K
191 BM_sizeCtor_IntList(1024) 35.52us 28.15K
192 BM_fillCtor_IntList(16) 269.86ns 3.71M
193 BM_fillCtor_IntList(128) 2.12us 470.70K
194 BM_fillCtor_IntList(1024) 46.59us 21.47K
195 BM_insertFront_IntList(16) 18.88ns 52.95M
196 BM_insertFront_IntList(128) 19.67ns 50.85M
197 BM_insertFront_IntList(1024) 18.79ns 53.22M
198 BM_insertFront_IntList(10240) 20.47ns 48.85M
199 BM_insertFront_IntList(102400) 17.43ns 57.37M
200 BM_insertFront_IntList(1024000) 17.65ns 56.65M
201 BM_pushBack_IntList(16) 20.45ns 48.89M
202 BM_pushBack_IntList(128) 21.54ns 46.42M
203 BM_pushBack_IntList(1024) 20.14ns 49.64M
204 BM_pushBack_IntList(10240) 21.21ns 47.15M
205 BM_pushBack_IntList(102400) 18.53ns 53.98M
206 BM_pushBack_IntList(1024000) 22.16ns 45.12M
207 BM_zzInitRNG_IntDeque 1.14us 879.33K
208 BM_defaultCtor_IntDeque 33.14ns 30.18M
209 BM_sizeCtor_IntDeque(16) 44.34ns 22.56M
210 BM_sizeCtor_IntDeque(128) 81.28ns 12.30M
211 BM_sizeCtor_IntDeque(1024) 338.93ns 2.95M
212 BM_fillCtor_IntDeque(16) 52.18ns 19.16M
213 BM_fillCtor_IntDeque(128) 76.01ns 13.16M
214 BM_fillCtor_IntDeque(1024) 329.99ns 3.03M
215 BM_insertFront_IntDeque(16) 2.56ns 390.51M
216 BM_insertFront_IntDeque(128) 2.48ns 403.57M
217 BM_insertFront_IntDeque(1024) 2.31ns 432.60M
218 BM_insertFront_IntDeque(10240) 2.30ns 434.90M
219 BM_insertFront_IntDeque(102400) 2.32ns 431.00M
220 BM_insertFront_IntDeque(1024000) 2.36ns 423.26M
221 BM_pushBack_IntDeque(16) 935.50ps 1.07G
222 BM_pushBack_IntDeque(128) 935.72ps 1.07G
223 BM_pushBack_IntDeque(1024) 942.23ps 1.06G
224 BM_pushBack_IntDeque(10240) 934.27ps 1.07G
225 BM_pushBack_IntDeque(102400) 947.61ps 1.06G
226 BM_pushBack_IntDeque(1024000) 993.47ps 1.01G
227 BM_zzInitRNG_StringVector 1.03us 966.54K
228 BM_defaultCtor_StringVector 911.27ps 1.10G
229 BM_sizeCtor_StringVector(16) 35.94ns 27.83M
230 BM_sizeCtor_StringVector(128) 233.07ns 4.29M
231 BM_sizeCtor_StringVector(1024) 1.83us 546.61K
232 BM_fillCtor_StringVector(16) 10.30us 97.07K
233 BM_fillCtor_StringVector(128) 21.56us 46.37K
234 BM_fillCtor_StringVector(1024) 128.63us 7.77K
235 BM_reserve_StringVector(16) 45.76ns 21.85M
236 BM_reserve_StringVector(128) 60.52ns 16.52M
237 BM_reserve_StringVector(1024) 59.59ns 16.78M
238 BM_insertFront_StringVector(16) 124.99us 8.00K
239 BM_insertFront_StringVector(128) 120.57us 8.29K
240 BM_insertFront_StringVector(1024) 126.47us 7.91K
241 BM_insertFront_StringVector(10240) 153.43us 6.52K
242 BM_insertFront_StringVector(102400) 380.73us 2.63K
243 BM_insertFront_StringVector(1024000) 3.96ms 252.31
244 BM_pushBack_StringVector(16) 40.16ns 24.90M
245 BM_pushBack_StringVector(128) 41.94ns 23.85M
246 BM_pushBack_StringVector(1024) 36.92ns 27.08M
247 BM_pushBack_StringVector(10240) 18.19ns 54.99M
248 BM_pushBack_StringVector(102400) 41.21ns 24.27M
249 BM_pushBack_StringVector(1024000) 234.95ns 4.26M
250 BM_zzInitRNG_StringFBVector 1.05us 956.06K
251 BM_defaultCtor_StringFBVector 911.25ps 1.10G
252 BM_sizeCtor_StringFBVector(16) 38.40ns 26.04M
253 BM_sizeCtor_StringFBVector(128) 202.10ns 4.95M
254 BM_sizeCtor_StringFBVector(1024) 1.68us 593.56K
255 BM_fillCtor_StringFBVector(16) 6.65us 150.29K
256 BM_fillCtor_StringFBVector(128) 14.76us 67.76K
257 BM_fillCtor_StringFBVector(1024) 117.60us 8.50K
258 BM_reserve_StringFBVector(16) 60.40ns 16.56M
259 BM_reserve_StringFBVector(128) 62.28ns 16.06M
260 BM_reserve_StringFBVector(1024) 66.76ns 14.98M
261 BM_insertFront_StringFBVector(16) 126.51us 7.90K
262 BM_insertFront_StringFBVector(128) 121.29us 8.24K
263 BM_insertFront_StringFBVector(1024) 129.81us 7.70K
264 BM_insertFront_StringFBVector(10240) 148.77us 6.72K
265 BM_insertFront_StringFBVector(102400) 380.46us 2.63K
266 BM_insertFront_StringFBVector(1024000) 3.73ms 268.02
267 BM_pushBack_StringFBVector(16) 11.89ns 84.13M
268 BM_pushBack_StringFBVector(128) 20.32ns 49.20M
269 BM_pushBack_StringFBVector(1024) 47.91ns 20.87M
270 BM_pushBack_StringFBVector(10240) 39.74ns 25.16M
271 BM_pushBack_StringFBVector(102400) 36.86ns 27.13M
272 BM_pushBack_StringFBVector(1024000) 285.22ns 3.51M
273 BM_zzInitRNG_StringSmallVector 1.04us 965.73K
274 BM_defaultCtor_StringSmallVector 607.54ps 1.65G
275 BM_sizeCtor_StringSmallVector(16) 44.30ns 22.57M
276 BM_sizeCtor_StringSmallVector(128) 234.40ns 4.27M
277 BM_sizeCtor_StringSmallVector(1024) 1.96us 510.33K
278 BM_fillCtor_StringSmallVector(16) 6.12us 163.46K
279 BM_fillCtor_StringSmallVector(128) 18.65us 53.63K
280 BM_fillCtor_StringSmallVector(1024) 132.36us 7.56K
281 BM_reserve_StringSmallVector(16) 43.86ns 22.80M
282 BM_reserve_StringSmallVector(128) 51.03ns 19.60M
283 BM_reserve_StringSmallVector(1024) 48.61ns 20.57M
284 BM_insertFront_StringSmallVector(16) 127.32us 7.85K
285 BM_insertFront_StringSmallVector(128) 118.93us 8.41K
286 BM_insertFront_StringSmallVector(1024) 130.04us 7.69K
287 BM_insertFront_StringSmallVector(10240) 143.89us 6.95K
288 BM_insertFront_StringSmallVector(102400) 386.40us 2.59K
289 BM_insertFront_StringSmallVector(1024000) 3.74ms 267.73
290 BM_pushBack_StringSmallVector(16) 50.77ns 19.70M
291 BM_pushBack_StringSmallVector(128) 44.12ns 22.67M
292 BM_pushBack_StringSmallVector(1024) 45.62ns 21.92M
293 BM_pushBack_StringSmallVector(10240) 69.06ns 14.48M
294 BM_pushBack_StringSmallVector(102400) 139.62ns 7.16M
295 BM_pushBack_StringSmallVector(1024000) 445.65ns 2.24M
296 BM_zzInitRNG_StringList 1.17us 854.00K
297 BM_defaultCtor_StringList 911.39ps 1.10G
298 BM_sizeCtor_StringList(16) 309.90ns 3.23M
299 BM_sizeCtor_StringList(128) 3.18us 314.57K
300 BM_sizeCtor_StringList(1024) 41.72us 23.97K
301 BM_fillCtor_StringList(16) 7.12us 140.54K
302 BM_fillCtor_StringList(128) 19.22us 52.04K
303 BM_fillCtor_StringList(1024) 160.20us 6.24K
304 BM_insertFront_StringList(16) 27.71ns 36.09M
305 BM_insertFront_StringList(128) 51.34ns 19.48M
306 BM_insertFront_StringList(1024) 55.53ns 18.01M
307 BM_insertFront_StringList(10240) 24.62ns 40.62M
308 BM_insertFront_StringList(102400) 25.63ns 39.02M
309 BM_insertFront_StringList(1024000) 341.85ns 2.93M
310 BM_pushBack_StringList(16) 28.69ns 34.85M
311 BM_pushBack_StringList(128) 29.11ns 34.36M
312 BM_pushBack_StringList(1024) 33.28ns 30.05M
313 BM_pushBack_StringList(10240) 26.47ns 37.78M
314 BM_pushBack_StringList(102400) 48.51ns 20.62M
315 BM_pushBack_StringList(1024000) 75.97ns 13.16M
316 BM_zzInitRNG_StringDeque 1.17us 852.21K
317 BM_defaultCtor_StringDeque 39.44ns 25.36M
318 BM_sizeCtor_StringDeque(16) 88.29ns 11.33M
319 BM_sizeCtor_StringDeque(128) 444.53ns 2.25M
320 BM_sizeCtor_StringDeque(1024) 6.20us 161.17K
321 BM_fillCtor_StringDeque(16) 6.82us 146.73K
322 BM_fillCtor_StringDeque(128) 16.95us 58.99K
323 BM_fillCtor_StringDeque(1024) 121.97us 8.20K
324 BM_insertFront_StringDeque(16) 10.75ns 92.98M
325 BM_insertFront_StringDeque(128) 40.83ns 24.49M
326 BM_insertFront_StringDeque(1024) 10.26ns 97.43M
327 BM_insertFront_StringDeque(10240) 37.85ns 26.42M
328 BM_insertFront_StringDeque(102400) 34.75ns 28.78M
329 BM_insertFront_StringDeque(1024000) 39.31ns 25.44M
330 BM_pushBack_StringDeque(16) 11.32ns 88.31M
331 BM_pushBack_StringDeque(128) 11.93ns 83.80M
332 BM_pushBack_StringDeque(1024) 10.41ns 96.02M
333 BM_pushBack_StringDeque(10240) 9.83ns 101.72M
334 BM_pushBack_StringDeque(102400) 64.98ns 15.39M
335 BM_pushBack_StringDeque(1024000) 33.45ns 29.89M
336 BM_zzInitRNG_FBStringVector 1.17us 855.50K
337 BM_defaultCtor_FBStringVector 989.77ps 1.01G
338 BM_sizeCtor_FBStringVector(16) 35.38ns 28.26M
339 BM_sizeCtor_FBStringVector(128) 180.30ns 5.55M
340 BM_sizeCtor_FBStringVector(1024) 1.21us 823.15K
341 BM_fillCtor_FBStringVector(16) 6.42us 155.85K
342 BM_fillCtor_FBStringVector(128) 8.90us 112.32K
343 BM_fillCtor_FBStringVector(1024) 36.57us 27.35K
344 BM_reserve_FBStringVector(16) 50.12ns 19.95M
345 BM_reserve_FBStringVector(128) 50.09ns 19.96M
346 BM_reserve_FBStringVector(1024) 53.58ns 18.66M
347 BM_insertFront_FBStringVector(16) 105.90us 9.44K
348 BM_insertFront_FBStringVector(128) 102.06us 9.80K
349 BM_insertFront_FBStringVector(1024) 103.67us 9.65K
350 BM_insertFront_FBStringVector(10240) 122.63us 8.15K
351 BM_insertFront_FBStringVector(102400) 312.48us 3.20K
352 BM_insertFront_FBStringVector(1024000) 2.30ms 434.80
353 BM_pushBack_FBStringVector(16) 10.18ns 98.26M
354 BM_pushBack_FBStringVector(128) 10.13ns 98.75M
355 BM_pushBack_FBStringVector(1024) 10.14ns 98.62M
356 BM_pushBack_FBStringVector(10240) 11.60ns 86.19M
357 BM_pushBack_FBStringVector(102400) 8.47ns 118.02M
358 BM_pushBack_FBStringVector(1024000) 88.01ns 11.36M
359 BM_zzInitRNG_FBStringFBVector 1.03us 971.03K
360 BM_defaultCtor_FBStringFBVector 911.25ps 1.10G
361 BM_sizeCtor_FBStringFBVector(16) 33.53ns 29.82M
362 BM_sizeCtor_FBStringFBVector(128) 135.17ns 7.40M
363 BM_sizeCtor_FBStringFBVector(1024) 951.05ns 1.05M
364 BM_fillCtor_FBStringFBVector(16) 5.71us 175.27K
365 BM_fillCtor_FBStringFBVector(128) 8.11us 123.37K
366 BM_fillCtor_FBStringFBVector(1024) 37.95us 26.35K
367 BM_reserve_FBStringFBVector(16) 54.53ns 18.34M
368 BM_reserve_FBStringFBVector(128) 51.41ns 19.45M
369 BM_reserve_FBStringFBVector(1024) 55.52ns 18.01M
370 BM_insertFront_FBStringFBVector(16) 58.80us 17.01K
371 BM_insertFront_FBStringFBVector(128) 58.45us 17.11K
372 BM_insertFront_FBStringFBVector(1024) 59.08us 16.93K
373 BM_insertFront_FBStringFBVector(10240) 69.85us 14.32K
374 BM_insertFront_FBStringFBVector(102400) 176.99us 5.65K
375 BM_insertFront_FBStringFBVector(1024000) 4.07ms 245.84
376 BM_pushBack_FBStringFBVector(16) 4.19ns 238.39M
377 BM_pushBack_FBStringFBVector(128) 3.76ns 265.90M
378 BM_pushBack_FBStringFBVector(1024) 4.68ns 213.66M
379 BM_pushBack_FBStringFBVector(10240) 3.24ns 309.08M
380 BM_pushBack_FBStringFBVector(102400) 3.17ns 315.07M
381 BM_pushBack_FBStringFBVector(1024000) 25.88ns 38.65M
382 ============================================================================
383 */
384 // clang-format on
STL namespace.
int main(int argc, char **argv)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void runBenchmarks()
Definition: Benchmark.cpp:456
vector< folly::fbstring > FBStringVector
vector< std::string > StringVector
char ** argv
deque< int > IntDeque
list< int > IntList
deque< std::string > StringDeque
list< std::string > StringList
vector< int > IntVector