|
1 | 1 |
|
| 2 | +#include <string> |
2 | 3 | #include <benchmark/benchmark.h> |
3 | 4 |
|
4 | | -#include "TestMirrorProvider.h" |
5 | | -#include "GlobalTestUtils.h" |
6 | | -#include "../../CxxTestProps/inc/Person.h" |
7 | | -#include "../../CxxTestProps/inc/Complex.h" |
| 5 | +#include "RTLibInterface.h" |
| 6 | + |
| 7 | + |
| 8 | +#if defined(_MSC_VER) |
| 9 | +# define NOINLINE __declspec(noinline) |
| 10 | +#elif defined(__GNUC__) |
| 11 | +# define NOINLINE __attribute__((noinline)) |
| 12 | +#else |
| 13 | +# define NOINLINE |
| 14 | +#endif |
| 15 | + |
| 16 | +namespace rtl_bench { |
| 17 | + |
| 18 | + static std::optional<std::string> g_msg; |
| 19 | + |
| 20 | + NOINLINE void sendMessage(const char* pMsgStr) |
| 21 | + { |
| 22 | + g_msg = pMsgStr; |
| 23 | + } |
| 24 | + |
| 25 | + const rtl::CxxMirror& cxx_mirror() { |
| 26 | + static rtl::CxxMirror m = rtl::CxxMirror({ |
| 27 | + rtl::type().function("sendMessage").build(sendMessage) |
| 28 | + }); |
| 29 | + return m; |
| 30 | + } |
| 31 | +} |
8 | 32 |
|
9 | 33 | // Direct call vs. Reflected call |
10 | 34 | // ------------------------------------------------------------ |
11 | 35 | static void DirectCall(benchmark::State& state) |
12 | 36 | { |
13 | | - Person obj; |
14 | 37 | for (auto _ : state) { |
15 | | - benchmark::DoNotOptimize(complex::getMagnitude()); |
| 38 | + rtl_bench::sendMessage("direct"); |
| 39 | + benchmark::ClobberMemory(); |
16 | 40 | } |
17 | 41 | } |
18 | 42 |
|
19 | 43 | static void ReflectedCall(benchmark::State& state) |
20 | 44 | { |
21 | | - rtl::Function getMagnitude = test_mirror::cxx().mirror().getFunction(test_utils::str_complex,test_utils::str_getMagnitude).value(); |
| 45 | + rtl::Function sendMessage = rtl_bench::cxx_mirror().getFunction("sendMessage").value(); |
22 | 46 | for (auto _ : state) {; |
23 | | - benchmark::DoNotOptimize(getMagnitude.bind().call()); |
| 47 | + sendMessage.bind().call("reflected"); |
| 48 | + benchmark::ClobberMemory(); |
24 | 49 | } |
25 | 50 | } |
26 | 51 |
|
|
0 commit comments