folly copyright 2015 -> copyright 2016
[folly.git] / folly / test / function_benchmark / benchmark_impl.cpp
1 /*
2  * Copyright 2016 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 #include <folly/test/function_benchmark/benchmark_impl.h>
18
19 #include <folly/test/function_benchmark/test_functions.h>
20
21 /*
22  * These functions are defined in a separate file so that gcc won't be able to
23  * inline them and optimize away the indirect calls.
24  */
25
26 void BM_fn_ptr_invoke_impl(int iters, void (*fn)()) {
27   for (int n = 0; n < iters; ++n) {
28     fn();
29   }
30 }
31
32 void BM_std_function_invoke_impl(int iters,
33                                  const std::function<void()>& fn) {
34   for (int n = 0; n < iters; ++n) {
35     fn();
36   }
37 }
38
39 void BM_mem_fn_invoke_impl(int iters,
40                            TestClass* tc,
41                            void (TestClass::*memfn)()) {
42   for (int n = 0; n < iters; ++n) {
43     (tc->*memfn)();
44   }
45 }
46
47 void BM_virtual_fn_invoke_impl(int iters, VirtualClass* vc) {
48   for (int n = 0; n < iters; ++n) {
49     vc->doNothing();
50   }
51 }