11
22#include < iostream>
3+ #include < optional>
34#include < functional>
4- #include " StandardCall.h"
55
6- extern std::optional<std::string> g_work_done;
6+ #include " BenchMark.h"
7+ #include " StandardCall.h"
78
89namespace
910{
@@ -19,39 +20,22 @@ namespace
1920 };
2021}
2122
22- namespace
23+
24+ namespace bm
2325{
24- static bm::Node node ;
26+ extern void sendMessage (argStr_t) ;
2527
26- static std::function SendMessage = [](bm::argStr_t& pMsg)
27- {
28- volatile auto * p = &pMsg;
29- static_cast <void >(p);
30- bm::sendMessage (pMsg);
31- };
28+ extern retStr_t getMessage (argStr_t);
3229
33- static std::function NodeSendMessage = [](bm::argStr_t& pMsg)
34- {
35- volatile auto * p = &pMsg;
36- static_cast <void >(p);
37- node.sendMessage (pMsg);
38- };
30+ extern std::optional<std::string> g_work_done;
3931
40- static std::function GetMessage = [](bm::argStr_t& pMsg)
41- {
42- auto retMsg = bm::getMessage (pMsg);
43- volatile auto * p = &retMsg;
44- static_cast <void >(p);
45- return retMsg;
46- };
32+ extern std::function<void (argStr_t&)> SendMessage;
4733
48- static std::function NodeGetMessage = [](bm::argStr_t& pMsg)
49- {
50- auto retMsg = node.getMessage (pMsg);
51- volatile auto * p = &retMsg;
52- static_cast <void >(p);
53- return retMsg;
54- };
34+ extern std::function<void (argStr_t&)> NodeSendMessage;
35+
36+ extern std::function<retStr_t(argStr_t&)> GetMessage;
37+
38+ extern std::function<retStr_t(argStr_t&)> NodeGetMessage;
5539}
5640
5741
@@ -60,7 +44,7 @@ void DirectCall::noReturn(benchmark::State& state)
6044 for (auto _: state)
6145 {
6246 bm::sendMessage (bm::g_longStr);
63- benchmark::DoNotOptimize (g_work_done->c_str ());
47+ benchmark::DoNotOptimize (bm:: g_work_done->c_str ());
6448 }
6549}
6650
@@ -75,14 +59,13 @@ void DirectCall::withReturn(benchmark::State& state)
7559}
7660
7761
78-
7962void StdFuncCall::noReturn (benchmark::State& state)
8063{
8164 static auto _=_new_line ();
8265 for (auto _: state)
8366 {
84- SendMessage (bm::g_longStr);
85- benchmark::DoNotOptimize (g_work_done->c_str ());
67+ bm:: SendMessage (bm::g_longStr);
68+ benchmark::DoNotOptimize (bm:: g_work_done->c_str ());
8669 }
8770}
8871
@@ -92,8 +75,8 @@ void StdFuncMethodCall::noReturn(benchmark::State& state)
9275 static auto _=_new_line ();
9376 for (auto _: state)
9477 {
95- NodeSendMessage (bm::g_longStr);
96- benchmark::DoNotOptimize (g_work_done->c_str ());
78+ bm:: NodeSendMessage (bm::g_longStr);
79+ benchmark::DoNotOptimize (bm:: g_work_done->c_str ());
9780 }
9881}
9982
@@ -103,7 +86,7 @@ void StdFuncCall::withReturn(benchmark::State& state)
10386 static auto _=_new_line ();
10487 for (auto _: state)
10588 {
106- benchmark::DoNotOptimize (GetMessage (bm::g_longStr));
89+ benchmark::DoNotOptimize (bm:: GetMessage (bm::g_longStr));
10790 }
10891}
10992
@@ -113,6 +96,6 @@ void StdFuncMethodCall::withReturn(benchmark::State& state)
11396 static auto _=_new_line ();
11497 for (auto _: state)
11598 {
116- benchmark::DoNotOptimize (NodeGetMessage (bm::g_longStr));
99+ benchmark::DoNotOptimize (bm:: NodeGetMessage (bm::g_longStr));
117100 }
118101}
0 commit comments