9dceb495b4d70fe3d7435a0001bd2035fb212bfd
[folly.git] / folly / test / function_benchmark / benchmark_impl.cpp
1 // Copyright 2004-present Facebook.  All rights reserved.
2 #include "folly/test/function_benchmark/benchmark_impl.h"
3
4 #include "folly/test/function_benchmark/test_functions.h"
5
6 /*
7  * These functions are defined in a separate file so that gcc won't be able to
8  * inline them and optimize away the indirect calls.
9  */
10
11 void BM_fn_ptr_invoke_impl(int iters, void (*fn)()) {
12   for (int n = 0; n < iters; ++n) {
13     fn();
14   }
15 }
16
17 void BM_std_function_invoke_impl(int iters,
18                                  const std::function<void()>& fn) {
19   for (int n = 0; n < iters; ++n) {
20     fn();
21   }
22 }
23
24 void BM_mem_fn_invoke_impl(int iters,
25                            TestClass* tc,
26                            void (TestClass::*memfn)()) {
27   for (int n = 0; n < iters; ++n) {
28     (tc->*memfn)();
29   }
30 }
31
32 void BM_virtual_fn_invoke_impl(int iters, VirtualClass* vc) {
33   for (int n = 0; n < iters; ++n) {
34     vc->doNothing();
35   }
36 }