Pull from FB rev 63ce89e2f2301e6bba44a111cc7d4218022156f6
[folly.git] / folly / test / function_benchmark / benchmark_impl.h
1 // Copyright 2004-present Facebook.  All rights reserved.
2 #ifndef BENCHMARK_IMPL_H_
3 #define BENCHMARK_IMPL_H_
4
5 #include <functional>
6
7 class TestClass;
8 class VirtualClass;
9
10 void BM_fn_ptr_invoke_impl(int iters, void (*fn)());
11 void BM_std_function_invoke_impl(int iters, const std::function<void()>& fn);
12 void BM_mem_fn_invoke_impl(int iters,
13                            TestClass* tc,
14                            void (TestClass::*memfn)());
15 void BM_virtual_fn_invoke_impl(int iters, VirtualClass* vc);
16
17 // Inlined version of BM_fn_ptr_invoke_impl().
18 // The compiler could potentially even optimize the call to the function
19 // pointer if it is a constexpr.
20 inline void BM_fn_ptr_invoke_inlined_impl(int iters, void (*fn)()) {
21   for (int n = 0; n < iters; ++n) {
22     fn();
23   }
24 }
25
26 // Invoke a function object as a template parameter.
27 // This can be used to directly invoke lambda functions
28 template<typename T>
29 void BM_invoke_fn_template_impl(int iters, const T& fn) {
30   for (int n = 0; n < iters; ++n) {
31     fn();
32   }
33 }
34
35 #endif // BENCHMARK_IMPL_H_