summaryrefslogtreecommitdiff
path: root/absl/functional/function_type_benchmark.cc
diff options
context:
space:
mode:
authorGravatar Dino Radakovic <dinor@google.com>2022-06-16 16:42:34 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-06-16 16:43:07 -0700
commitb7ceff06d2358d09ba967c00f526b6143f207d56 (patch)
treec8350bffed0225834428b7b889b4b905ce350955 /absl/functional/function_type_benchmark.cc
parent53a90f079af7ab491530d432bb318a95371ba877 (diff)
Release absl::AnyInvocable
AnyInvocable is a C++11 compatible equivalent of the C++23 [std::move_only_function](https://en.cppreference.com/w/cpp/utility/functional/move_only_function/move_only_function). Although this implementation matches an intermediate draft revision of the standard (http://wg21.link/p0288r5), it is neither a standard tracking type nor a seamless backfill type. PiperOrigin-RevId: 455494585 Change-Id: If01565f8eecc78eee38fb794ef142b32b31abc7c
Diffstat (limited to 'absl/functional/function_type_benchmark.cc')
-rw-r--r--absl/functional/function_type_benchmark.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/absl/functional/function_type_benchmark.cc b/absl/functional/function_type_benchmark.cc
index 1b27eebf..03dc31d8 100644
--- a/absl/functional/function_type_benchmark.cc
+++ b/absl/functional/function_type_benchmark.cc
@@ -18,6 +18,7 @@
#include "benchmark/benchmark.h"
#include "absl/base/attributes.h"
+#include "absl/functional/any_invocable.h"
#include "absl/functional/function_ref.h"
namespace absl {
@@ -62,6 +63,12 @@ void BM_TrivialFunctionRef(benchmark::State& state) {
}
BENCHMARK(BM_TrivialFunctionRef);
+void BM_TrivialAnyInvocable(benchmark::State& state) {
+ ConstructAndCallFunctionBenchmark<AnyInvocable<void()>>(state,
+ TrivialFunctor{});
+}
+BENCHMARK(BM_TrivialAnyInvocable);
+
void BM_LargeStdFunction(benchmark::State& state) {
ConstructAndCallFunctionBenchmark<std::function<void()>>(state,
LargeFunctor{});
@@ -73,6 +80,13 @@ void BM_LargeFunctionRef(benchmark::State& state) {
}
BENCHMARK(BM_LargeFunctionRef);
+
+void BM_LargeAnyInvocable(benchmark::State& state) {
+ ConstructAndCallFunctionBenchmark<AnyInvocable<void()>>(state,
+ LargeFunctor{});
+}
+BENCHMARK(BM_LargeAnyInvocable);
+
void BM_FunPtrStdFunction(benchmark::State& state) {
ConstructAndCallFunctionBenchmark<std::function<void()>>(state, FreeFunction);
}
@@ -83,6 +97,11 @@ void BM_FunPtrFunctionRef(benchmark::State& state) {
}
BENCHMARK(BM_FunPtrFunctionRef);
+void BM_FunPtrAnyInvocable(benchmark::State& state) {
+ ConstructAndCallFunctionBenchmark<AnyInvocable<void()>>(state, FreeFunction);
+}
+BENCHMARK(BM_FunPtrAnyInvocable);
+
// Doesn't include construction or copy overhead in the loop.
template <typename Function, typename Callable, typename... Args>
void CallFunctionBenchmark(benchmark::State& state, const Callable& c,
@@ -114,6 +133,12 @@ void BM_TrivialArgsFunctionRef(benchmark::State& state) {
}
BENCHMARK(BM_TrivialArgsFunctionRef);
+void BM_TrivialArgsAnyInvocable(benchmark::State& state) {
+ CallFunctionBenchmark<AnyInvocable<void(int, int, int)>>(
+ state, FunctorWithTrivialArgs{}, 1, 2, 3);
+}
+BENCHMARK(BM_TrivialArgsAnyInvocable);
+
struct FunctorWithNonTrivialArgs {
void operator()(std::string a, std::string b, std::string c) const {
benchmark::DoNotOptimize(&a);
@@ -138,6 +163,14 @@ void BM_NonTrivialArgsFunctionRef(benchmark::State& state) {
}
BENCHMARK(BM_NonTrivialArgsFunctionRef);
+void BM_NonTrivialArgsAnyInvocable(benchmark::State& state) {
+ std::string a, b, c;
+ CallFunctionBenchmark<
+ AnyInvocable<void(std::string, std::string, std::string)>>(
+ state, FunctorWithNonTrivialArgs{}, a, b, c);
+}
+BENCHMARK(BM_NonTrivialArgsAnyInvocable);
+
} // namespace
ABSL_NAMESPACE_END
} // namespace absl