template< -> template <
[folly.git] / folly / test / function_benchmark / benchmark_impl.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <functional>
20
21 #include <folly/Function.h>
22
23 class TestClass;
24 class VirtualClass;
25
26 void BM_fn_ptr_invoke_impl(int iters, void (*fn)());
27 void BM_std_function_invoke_impl(int iters, const std::function<void()>& fn);
28 void BM_Function_invoke_impl(int iters,
29                              const folly::Function<void() const>& fn);
30 void BM_mem_fn_invoke_impl(int iters,
31                            TestClass* tc,
32                            void (TestClass::*memfn)());
33 void BM_virtual_fn_invoke_impl(int iters, VirtualClass* vc);
34
35 // Inlined version of BM_fn_ptr_invoke_impl().
36 // The compiler could potentially even optimize the call to the function
37 // pointer if it is a constexpr.
38 inline void BM_fn_ptr_invoke_inlined_impl(int iters, void (*fn)()) {
39   for (int n = 0; n < iters; ++n) {
40     fn();
41   }
42 }
43
44 // Invoke a function object as a template parameter.
45 // This can be used to directly invoke lambda functions
46 template <typename T>
47 void BM_invoke_fn_template_impl(int iters, const T& fn) {
48   for (int n = 0; n < iters; ++n) {
49     fn();
50   }
51 }