Introducing folly::Function
[folly.git] / folly / test / function_benchmark / main.cpp
index b08367193a912da901c49ffe4f618582bf551114..171d7aedaba1bab028557759f7f8b725ba20c62b 100644 (file)
@@ -45,6 +45,11 @@ BENCHMARK(std_function_invoke, iters) {
   BM_std_function_invoke_impl(iters, doNothing);
 }
 
+// Invoking a function through a folly::Function object
+BENCHMARK(Function_invoke, iters) {
+  BM_Function_invoke_impl(iters, doNothing);
+}
+
 // Invoking a member function through a member function pointer
 BENCHMARK(mem_fn_invoke, iters) {
   TestClass tc;
@@ -111,6 +116,15 @@ BENCHMARK(std_function_create_invoke, iters) {
   }
 }
 
+// Creating a folly::Function object from a function pointer, and
+// invoking it
+BENCHMARK(Function_create_invoke, iters) {
+  for (size_t n = 0; n < iters; ++n) {
+    folly::Function<void()> fn = doNothing;
+    fn();
+  }
+}
+
 // Creating a pointer-to-member and invoking it
 BENCHMARK(mem_fn_create_invoke, iters) {
   TestClass tc;
@@ -155,6 +169,14 @@ BENCHMARK(scope_guard_std_function_rvalue, iters) {
   }
 }
 
+// Using ScopeGuard to invoke a folly::Function,
+// 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));
+  }
+}
+
 // Using ScopeGuard to invoke a function pointer
 BENCHMARK(scope_guard_fn_ptr, iters) {
   for (size_t n = 0; n < iters; ++n) {