26 using namespace folly;
37 std::map<int, std::string>
bmMap;
46 for (
size_t i = 0;
i < iters; ++
i) {
47 bmMap[
i] =
"teststring";
52 vec_one.resize(iters);
53 vec_two.resize(iters);
57 vec_char.resize(iters);
59 vec_char.begin(), vec_char.end(), [] {
return Random::rand32(128); });
71 sumKeys += key_val_pair.first;
72 sumValues += key_val_pair.second;
86 std::for_each(bmMap.begin(), bmMap.end(), [&](
auto& key_val_pair) {
87 sumKeys += key_val_pair.first;
88 sumValues += key_val_pair.second;
101 for (
auto& key_val_pair : bmMap) {
102 sumKeys += key_val_pair.first;
103 sumValues += key_val_pair.second;
117 for (
auto iter = bmMap.begin(); iter != bmMap.end(); ++iter) {
118 sumKeys += iter->first;
119 sumValues += iter->second;
134 const int k = key_val_pair.first;
150 std::for_each(bmMap.begin(), bmMap.end(), [&](
auto& key_val_pair) {
151 const int k = key_val_pair.first;
167 for (
auto& key_val_pair : bmMap) {
168 const int k = key_val_pair.first;
184 for (
auto iter = bmMap.begin(); iter != bmMap.end(); ++iter) {
185 const int k = iter->first;
193 BENCHMARK(ForEachFunctionNoAssignWithIndexManipulation, iters) {
202 sumKeys += key_val_pair.first;
203 sumValues += key_val_pair.second;
209 BENCHMARK(StdForEachFunctionNoAssignWithIndexManipulation, iters) {
217 auto index = std::size_t{0};
218 std::for_each(bmMap.begin(), bmMap.end(), [&](
auto& key_val_pair) {
219 sumKeys += key_val_pair.first;
220 sumValues += key_val_pair.second;
227 BENCHMARK(RangeBasedForLoopNoAssignWithIndexManipulation, iters) {
235 auto index = std::size_t{0};
236 for (
auto& key_val_pair : bmMap) {
237 sumKeys += key_val_pair.first;
238 sumValues += key_val_pair.second;
260 auto index = std::size_t{0};
261 std::for_each(bmMap.begin(), bmMap.end(), [&](
auto& key_val_pair) {
262 *(vec_one.begin() + index++) = key_val_pair.first;
272 auto index = std::size_t{0};
273 for (
auto& key_val_pair : bmMap) {
274 *(vec_one.begin() + index++) = key_val_pair.first;
288 const int k = iter->first;
304 sumKeys += iter->first;
305 sumValues += iter->second;
325 for (
size_t i = 1;
i < iters; ++
i) {
339 for (
size_t i = iters;
i-- > 1;) {
356 for (
auto&
c : vec_char) {
368 for (
auto&
c : vec_char) {
399 sum += *it * it.index;
std::atomic< int64_t > sum(0)
#define FOR_EACH_KV(k, v, c)
std::map< int, std::string > bmMap
#define BENCHMARK_SUSPEND
int main(int argc, char **argv)
void setupBenchmark(size_t iters)
std::vector< int > vec_one
—— Concurrent Priority Queue Implementation ——
#define FOR_EACH_RANGE(i, begin, end)
void init(int *argc, char ***argv, bool removeFlags)
void setupCharVecBenchmark(size_t iters)
detail::RangeEnumerator< Range > enumerate(Range &&r)
std::vector< char > vec_char
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
auto dismissing(F f) -> invoke_result_t< F >
void for_each(T const &range, Function< void(typename T::value_type const &) const > const &func)
std::vector< int > vec_two
decltype(auto) FOLLY_CPP14_CONSTEXPR fetch(Sequence &&sequence, Index &&index)
#define FOR_EACH_RANGE_R(i, begin, end)
FOLLY_CPP14_CONSTEXPR Func for_each(Sequence &&sequence, Func func)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type