99namespace {
1010
1111 static const char * LONG_STR = " Lorem ipsum" ;
12- // dolor sit amet, consectetur adipiscing elit, sed do"
13- // "do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
14- // "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
15- // "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
16- // "eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id"
17- // "Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo";
12+ // dolor sit amet, consectetur adipiscing elit, sed do"
13+ // "do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
14+ // "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
15+ // "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
16+ // "eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id"
17+ // "Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo";
1818}
1919
2020// Pre-created string to isolate call overhead
21- static argStr_t g_longStr (LONG_STR);
21+ argStr_t g_longStr (LONG_STR);
22+
23+ extern decltype (&rtl_bench::getMessage) getMessagePtr;
24+ extern decltype (&rtl_bench::sendMessage) sendMessagePtr;
25+ extern decltype (&rtl_bench::Node::getMessage) getMessageNodePtr;
26+ extern decltype (&rtl_bench::Node::sendMessage) sendMessageNodePtr;
2227
2328namespace rtl_bench
2429{
30+ static Node* node = new Node();
31+
2532 void BenchMark::directCall_noReturn (benchmark::State& state)
2633 {
2734 for (auto _ : state)
2835 {
29- sendMessage (g_longStr);
36+ sendMessagePtr (g_longStr);
3037 benchmark::DoNotOptimize (g_msg);
3138 }
3239 }
@@ -35,7 +42,7 @@ namespace rtl_bench
3542 void BenchMark::stdFunctionCall_noReturn (benchmark::State& state)
3643 {
3744 static std::function sendMsg = [](argStr_t& pMsg) {
38- sendMessage (pMsg);
45+ sendMessagePtr (pMsg);
3946 };
4047
4148 for (auto _ : state)
@@ -45,12 +52,10 @@ namespace rtl_bench
4552 }
4653 }
4754
48-
4955 void BenchMark::stdFunctionMethodCall_noReturn (benchmark::State& state)
5056 {
51- Node* node = new Node ();
5257 static std::function sendMsg = [=](argStr_t& pMsg) {
53- node->sendMessage (pMsg);
58+ ( node->*sendMessageNodePtr) (pMsg);
5459 };
5560
5661 for (auto _ : state)
@@ -79,10 +84,7 @@ namespace rtl_bench
7984 void BenchMark::stdFunctionCall_withReturn (benchmark::State& state)
8085 {
8186 static std::function getMsg = [](argStr_t& pMsg) {
82- auto msgStr = getMessage (pMsg);
83- volatile auto * p = &msgStr;
84- static_cast <void >(p);
85- return msgStr;
87+ return getMessagePtr (pMsg);
8688 };
8789
8890 for (auto _ : state)
@@ -94,12 +96,8 @@ namespace rtl_bench
9496
9597 void BenchMark::stdFunctionMethodCall_withReturn (benchmark::State& state)
9698 {
97- static Node* node = new Node ();
9899 static std::function getMsg = [=](argStr_t& pMsg) {
99- auto msgStr = node->getMessage (pMsg);
100- volatile auto * p = &msgStr;
101- static_cast <void >(p);
102- return msgStr;
100+ return (node->*getMessageNodePtr)(pMsg);
103101 };
104102
105103 for (auto _ : state)
0 commit comments