proxygen
FBVectorBenchmarks.cpp.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-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 
22 BENCHMARK(BENCHFUN(zzInitRNG)) {
23  srand(seed);
24 }
25 
27  FOR_EACH_RANGE (i, 0, iters) {
28  VECTOR v;
30  }
31 }
32 
33 void BENCHFUN(sizeCtor)(int iters, int size) {
34  FOR_EACH_RANGE (i, 0, iters) {
35  VECTOR v(size);
37  }
38 }
42 
43 void BENCHFUN(fillCtor)(int iters, int size) {
44  FOR_EACH_RANGE (i, 0, iters) {
45  VECTOR v(size_t(size), randomObject<VECTOR::value_type>());
47  }
48 }
52 
53 #ifndef SKIP_RESERVE
54 void BENCHFUN(reserve)(int iters, int size) {
55  auto const obj = randomObject<VECTOR::value_type>();
56  FOR_EACH_RANGE (i, 0, iters) {
57  VECTOR v(random(0U, 1U), obj);
58  v.reserve(size);
59  }
60 }
64 #endif
65 
66 void BENCHFUN(insertFront)(int iters, int initialSize) {
67  BenchmarkSuspender braces;
68  auto const obj = randomObject<VECTOR::value_type>();
69  VECTOR v(initialSize, obj);
70  braces.dismissing([&]() {
71  FOR_EACH_RANGE (i, 0, iters) { v.insert(v.begin(), obj); }
72  });
73 }
74 
81 
82 void BENCHFUN(pushBack)(int iters, int initialSize) {
83  BenchmarkSuspender braces;
84  auto const obj = randomObject<VECTOR::value_type>();
85  VECTOR v(initialSize, obj);
86  braces.dismissing([&]() {
87  FOR_EACH_RANGE (i, 0, iters) { v.push_back(obj); }
88  });
89 }
90 
Integral2 random(Integral1 low, Integral2 up)
void BENCHFUN() defaultCtor(size_t iters, size_t)
auto v
void BENCHFUN() insertFront(int iters, int initialSize)
static const int seed
void BENCHFUN() sizeCtor(int iters, int size)
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
void BENCHFUN() reserve(int iters, int size)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
BENCHMARK(BENCHFUN(zzInitRNG))
void BENCHFUN() fillCtor(int iters, int size)
void BENCHFUN() pushBack(int iters, int initialSize)
#define VECTOR
#define BENCHMARK_PARAM(name, param)
Definition: Benchmark.h:417
#define BENCHFUN(F)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258