11
2+ #include < benchmark/benchmark.h>
3+
24#include " ReflectedCall.h"
35#include " RTLibInterface.h"
6+ #include " BenchMark.h"
47
5- namespace
8+ namespace cxx
69{
7- static const rtl::CxxMirror& cxx_mirror ()
8- {
9- static auto m = rtl::CxxMirror ({
10-
11- rtl::type ().function (" getMessage" ).build (bm::getMessage),
12-
13- rtl::type ().function (" sendMessage" ).build (bm::sendMessage),
14-
15- rtl::type ().record <bm::Node>(" Node" ).build (),
10+ extern const rtl::CxxMirror& mirror ();
11+ }
1612
17- rtl::type ().member <bm::Node>().method (" sendMessage" ).build (&bm::Node::sendMessage),
13+ namespace
14+ {
15+ static rtl::Function GetMessage = cxx::mirror().getFunction(" getMessage" ).value();
16+ static rtl::Function SendMessage = cxx::mirror().getFunction(" sendMessage" ).value();
1817
19- rtl::type ().member <bm::Node>().method (" getMessage" ).build (&bm::Node::getMessage)
20- });
21- return m;
22- }
18+ static rtl::Method NodeGetMessage = cxx::mirror().getRecord(" Node" )->getMethod (" getMessage" ).value();
19+ static rtl::Method NodeSendMessage = cxx::mirror().getRecord(" Node" )->getMethod (" sendMessage" ).value();
2320
24- static rtl::Record Node = cxx_mirror().getRecord( " Node " ).value();
25-
26- static rtl::RObject robj = Node.create<rtl::alloc::Stack> ().rObject ;
21+ static rtl::RObject nodeObj = []()
22+ {
23+ auto Node = cxx::mirror ().getRecord ( " Node " ). value () ;
2724
28- static rtl::Method NodeGetMessage = Node.getMethod( " getMessage " ).value() ;
25+ rtl::RObject robj = Node.create <rtl::alloc::Stack>(). rObject ;
2926
30- static rtl::Method NodeSendMessage = Node.getMethod(" sendMessage" ).value();
31-
32- static rtl::Function GetMessage = cxx_mirror().getFunction(" getMessage" ).value();
33-
34- static rtl::Function SendMessage = cxx_mirror().getFunction(" sendMessage" ).value();
27+ return std::move (robj);
28+ }();
3529}
3630
3731
38-
3932 namespace
4033 {
4134 static auto _test0 = []()
@@ -50,7 +43,7 @@ namespace
5043
5144 static auto _test1 = []()
5245 {
53- auto err = NodeSendMessage (robj )(bm::g_longStr).err ;
46+ auto err = NodeSendMessage (nodeObj )(bm::g_longStr).err ;
5447
5548 if (err != rtl::error::None) {
5649 std::cout << " [1] error: " << rtl::to_string (err) << " \n " ;
@@ -70,7 +63,7 @@ namespace
7063
7164 static auto _test3 = []()
7265 {
73- auto err = NodeGetMessage (robj )(bm::g_longStr).err ;
66+ auto err = NodeGetMessage (nodeObj )(bm::g_longStr).err ;
7467
7568 if (err != rtl::error::None) {
7669 std::cout << " [3] error: " << rtl::to_string (err) << " \n " ;
@@ -86,7 +79,7 @@ void ReflectedCall::noReturn(benchmark::State& state)
8679 static auto _=_test0 ();
8780 for (auto _: state) {
8881
89- auto error = SendMessage. bind (). call (bm::g_longStr).err ;
82+ auto error = SendMessage (bm::g_longStr).err ;
9083 benchmark::DoNotOptimize (error);
9184 }
9285}
@@ -97,7 +90,7 @@ void ReflectedCall::withReturn(benchmark::State& state)
9790 static auto _=_test2 ();
9891 for (auto _: state)
9992 {
100- auto error = GetMessage. bind (). call (bm::g_longStr).err ;
93+ auto error = GetMessage (bm::g_longStr).err ;
10194 benchmark::DoNotOptimize (error);
10295 }
10396}
@@ -108,7 +101,7 @@ void ReflectedMethodCall::noReturn(benchmark::State& state)
108101 static auto _=_test1 ();
109102 for (auto _: state)
110103 {
111- auto error = NodeSendMessage. bind (robj). call (bm::g_longStr).err ;
104+ auto error = NodeSendMessage (nodeObj) (bm::g_longStr).err ;
112105 benchmark::DoNotOptimize (error);
113106 }
114107}
@@ -119,7 +112,7 @@ void ReflectedMethodCall::withReturn(benchmark::State& state)
119112 static auto _=_test3 ();
120113 for (auto _: state)
121114 {
122- auto error = NodeGetMessage. bind (robj). call (bm::g_longStr).err ;
115+ auto error = NodeGetMessage (nodeObj) (bm::g_longStr).err ;
123116 benchmark::DoNotOptimize (error);
124117 }
125118}
0 commit comments