Just trying out one more combination
authorRajat Goel <rajatgoel2010@fb.com>
Sat, 22 Sep 2012 10:31:51 +0000 (03:31 -0700)
committerJordan DeLong <jdelong@fb.com>
Fri, 12 Oct 2012 04:33:58 +0000 (21:33 -0700)
Summary:
It seems it is not std::bind which is slow but the construction of
std::function from std::bind that is slow.

Test Plan: ran benchmarks

Reviewed By: delong.j@fb.com

FB internal diff: D581967

folly/test/function_benchmark/main.cpp

index 33610c9d8d613000764994e974481fe9e721e6f5..c345ac786c21cc63e9fd1fbc6d2cf41f8f53cdbc 100644 (file)
@@ -130,6 +130,15 @@ BENCHMARK(std_bind_create_invoke, iters) {
   }
 }
 
+// Using std::bind directly to invoke a member function
+BENCHMARK(std_bind_direct_invoke, iters) {
+  TestClass tc;
+  for (int n = 0; n < iters; ++n) {
+    auto fn = std::bind(&TestClass::doNothing, &tc);
+    fn();
+  }
+}
+
 // Using ScopeGuard to invoke a std::function
 BENCHMARK(scope_guard_std_function, iters) {
   std::function<void()> fn(doNothing);