Commit 7f38b123 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot 9

Add create-move-invoke benchmark for folly::Function

Summary: Adding a benchmark for one the most common scenarios (used in Futures, EventBase, fibers etc).

Reviewed By: yfeldblum

Differential Revision: D3106365

fb-gh-sync-id: 8cb55959b3803e8836ab5a5bdf43fdfc1db02d4c
fbshipit-source-id: 8cb55959b3803e8836ab5a5bdf43fdfc1db02d4c
parent e3774034
...@@ -282,6 +282,40 @@ BENCHMARK(return_code_noexcept, iters) { ...@@ -282,6 +282,40 @@ BENCHMARK(return_code_noexcept, iters) {
} }
} }
BENCHMARK_DRAW_LINE()
BENCHMARK(std_function_create_move_invoke, iters) {
LargeClass a;
for (size_t i = 0; i < iters; ++i) {
std::function<void()> f(a);
invoke(std::move(f));
}
}
BENCHMARK(Function_create_move_invoke, iters) {
LargeClass a;
for (size_t i = 0; i < iters; ++i) {
folly::Function<void()> f(a);
invoke(std::move(f));
}
}
BENCHMARK(std_function_create_move_invoke_ref, iters) {
LargeClass a;
for (size_t i = 0; i < iters; ++i) {
std::function<void()> f(std::ref(a));
invoke(std::move(f));
}
}
BENCHMARK(Function_create_move_invoke_ref, iters) {
LargeClass a;
for (size_t i = 0; i < iters; ++i) {
folly::Function<void()> f(std::ref(a));
invoke(std::move(f));
}
}
// main() // main()
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
...@@ -76,3 +76,18 @@ VirtualClass::~VirtualClass() { ...@@ -76,3 +76,18 @@ VirtualClass::~VirtualClass() {
void VirtualClass::doNothing() { void VirtualClass::doNothing() {
}; };
LargeClass::LargeClass() {
// Suppress unused field warning
data[0] = 42;
}
void LargeClass::operator()() const {}
void invoke(std::function<void()> f) {
f();
}
void invoke(folly::Function<void()> f) {
f();
}
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
#define TEST_FUNCTIONS_H_ #define TEST_FUNCTIONS_H_
#include <exception> #include <exception>
#include <functional>
#include <string> #include <string>
#include <folly/Function.h>
void doNothing(); void doNothing();
void throwException(); void throwException();
...@@ -29,6 +32,8 @@ std::string returnString(); ...@@ -29,6 +32,8 @@ std::string returnString();
std::string returnStringNoExcept() noexcept; std::string returnStringNoExcept() noexcept;
int returnCode(int value); int returnCode(int value);
int returnCodeNoExcept(int value) noexcept; int returnCodeNoExcept(int value) noexcept;
void invoke(std::function<void()>);
void invoke(folly::Function<void()>);
class TestClass { class TestClass {
public: public:
...@@ -41,4 +46,13 @@ class VirtualClass { ...@@ -41,4 +46,13 @@ class VirtualClass {
virtual void doNothing(); virtual void doNothing();
}; };
class LargeClass {
public:
LargeClass();
void operator()() const; // do nothing
private:
// Avoid small object optimization.
char data[1024];
};
#endif // TEST_FUNCTIONS_H_ #endif // TEST_FUNCTIONS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment