/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2011-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <folly/ScopeGuard.h>
#include <folly/portability/GFlags.h>
-using folly::ScopeGuard;
using folly::makeGuard;
// Declare the bm_max_iters flag from folly/Benchmark.cpp
BENCHMARK(scope_guard_std_function, iters) {
std::function<void()> fn(doNothing);
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard(fn);
+ auto g = makeGuard(fn);
(void)g;
}
}
// but create the ScopeGuard with an rvalue to a std::function
BENCHMARK(scope_guard_std_function_rvalue, iters) {
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard(std::function<void()>(doNothing));
+ auto g = makeGuard(std::function<void()>(doNothing));
(void)g;
}
}
// but create the ScopeGuard with an rvalue to a folly::Function
BENCHMARK(scope_guard_Function_rvalue, iters) {
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard(folly::Function<void()>(doNothing));
+ auto g = makeGuard(folly::Function<void()>(doNothing));
(void)g;
}
}
// Using ScopeGuard to invoke a function pointer
BENCHMARK(scope_guard_fn_ptr, iters) {
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard(doNothing);
+ auto g = makeGuard(doNothing);
(void)g;
}
}
// Using ScopeGuard to invoke a lambda that does nothing
BENCHMARK(scope_guard_lambda_noop, iters) {
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard([] {});
+ auto g = makeGuard([] {});
(void)g;
}
}
// Using ScopeGuard to invoke a lambda that invokes a function
BENCHMARK(scope_guard_lambda_function, iters) {
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard([] { doNothing(); });
+ auto g = makeGuard([] { doNothing(); });
(void)g;
}
}
BENCHMARK(scope_guard_lambda_local_var, iters) {
uint32_t count = 0;
for (size_t n = 0; n < iters; ++n) {
- ScopeGuard g = makeGuard([&] {
+ auto g = makeGuard([&] {
// Increment count if n is odd. Without this conditional check
// (i.e., if we just increment count each time through the loop),
// gcc is smart enough to optimize the entire loop away, and just set