1
1
2
- #include < benchmark/benchmark.h>
3
2
#include < rtl/rtl.h>
3
+ #include < benchmark/benchmark.h>
4
4
5
5
#include " BenchMark.h"
6
6
#include " ReflectedCallKnownReturn.h"
@@ -20,256 +20,183 @@ namespace
20
20
{
21
21
static const rtl::lambda_function<bm::argStr_t>& getMessage_lambda = []()
22
22
{
23
- // No validation is performed internally and lambda<signature_ts...>
24
- // will not return nullptr on signature mismatch. (by design)
25
- return *(cxx::mirror ().getFunction (" getMessage" )->get_lambda <bm::argStr_t>());
23
+ auto lambda_ptr = cxx::mirror ().getFunction (" getMessage" )->get_lambda <bm::argStr_t>();
24
+ if (!lambda_ptr) {
25
+ std::cerr << " [0] error: return-type mismatch.\n " ;
26
+ std::abort ();
27
+ }
28
+ return *lambda_ptr;
26
29
}();
27
30
28
31
static const rtl::lambda_function<bm::argStr_t>& sendMessage_lambda = []()
29
32
{
30
- // No validation is performed internally and lambda<signature_ts...>
31
- // will not return nullptr on signature mismatch. (by design)
32
- return *(cxx::mirror ().getFunction (" sendMessage" )->get_lambda <bm::argStr_t>());
33
+ auto lambda_ptr = cxx::mirror ().getFunction (" sendMessage" )->get_lambda <bm::argStr_t>();
34
+ if (!lambda_ptr) {
35
+ std::cerr << " [1] error: return-type mismatch.\n " ;
36
+ std::abort ();
37
+ }
38
+ return *lambda_ptr;
39
+
33
40
}();
34
41
35
42
static const rtl::lambda_method<bm::Node, bm::argStr_t>& getMessageOnNode_lambda = []()
36
43
{
37
- // No validation is performed internally and lambda<signature_ts...>
38
- // will not return nullptr on signature mismatch. (by design)
39
- return *(cxx::mirror ().getRecord (" Node" )->getMethod (" getMessage" )->get_lambda <bm::Node, bm::argStr_t>());
44
+ auto lambda_ptr = cxx::mirror ().getRecord (" Node" )->getMethod (" getMessage" )->get_lambda <bm::Node, bm::argStr_t>();
45
+ if (!lambda_ptr) {
46
+ std::cerr << " [2] error: return-type mismatch.\n " ;
47
+ std::abort ();
48
+ }
49
+ return *lambda_ptr;
40
50
}();
41
51
42
52
static const rtl::lambda_method<bm::Node, bm::argStr_t>& sendMessageOnNode_lambda = []()
43
53
{
44
- rtl::Record Node = cxx::mirror ().getRecord (" Node" ).value ();
45
- // No validation is performed internally and lambda<signature_ts...>
46
- // will not return nullptr on signature mismatch. (by design)
47
- return *(cxx::mirror ().getRecord (" Node" )->getMethod (" sendMessage" )->get_lambda <bm::Node, bm::argStr_t>());
54
+ auto lambda_ptr = cxx::mirror ().getRecord (" Node" )->getMethod (" sendMessage" )->get_lambda <bm::Node, bm::argStr_t>();
55
+ if (!lambda_ptr) {
56
+ std::cerr << " [3] error: return-type mismatch.\n " ;
57
+ std::abort ();
58
+ }
59
+ return *lambda_ptr;
48
60
}();
49
61
}
50
62
51
63
52
64
namespace
53
65
{
54
- static auto _test0 = []()
66
+ static auto functor_set = [](int n)
55
67
{
56
- if (!sendMessage_lambda.is_signature <bm::argStr_t>() ||
57
- !sendMessage_lambda.is_returning <void >())
58
- {
59
- std::cout << " [0] error: signature mismatch.\n " ;
60
- return false ;
68
+ if (!sendMessage_lambda.is_returning <void >()) {
69
+ std::cerr << " [0" << n <<" ] error: return-type mismatch.\n " ;
70
+ std::abort ();
61
71
}
62
- return true ;
72
+ // 'get_functor<return_t>': No validation is performed internally and this function
73
+ // will not return nullptr on return_t mismatch. (by design).
74
+ return sendMessage_lambda.get_functor <void >().f_ptr ();
63
75
};
64
76
65
- static auto _test1 = []()
77
+ static auto method_set = [](int n )
66
78
{
67
- if (!sendMessageOnNode_lambda.is_signature <bm::argStr_t >() ||
68
- !sendMessageOnNode_lambda. is_returning < void >())
69
- {
70
- std::cout << " [1] error: signature mismatch. \n " ;
71
- return false ;
72
- }
73
- return true ;
79
+ if (!sendMessageOnNode_lambda.is_returning < void >()) {
80
+ std::cerr << " [1 " << n << " ] error: return-type mismatch. \n " ;
81
+ std::abort ();
82
+ }
83
+ // 'get_functor<return_t>': No validation is performed internally and this function
84
+ // will not return nullptr on return_t mismatch. (by design).
85
+ return sendMessageOnNode_lambda. get_functor < void >(). f_ptr () ;
74
86
};
75
87
76
- static auto _test2 = []()
88
+ static auto functor_get = [](int n )
77
89
{
78
- if (!getMessage_lambda.is_signature <bm::argStr_t>() ||
79
- !getMessage_lambda.is_returning <bm::retStr_t>())
80
- {
81
- std::cout << " [2] error: signature mismatch.\n " ;
82
- return false ;
90
+ if (!getMessage_lambda.is_returning <bm::retStr_t>()) {
91
+ std::cerr << " [2" << n <<" ] error: return-type mismatch.\n " ;
92
+ std::abort ();
83
93
}
84
- return true ;
94
+ // 'get_functor<return_t>': No validation is performed internally and this function
95
+ // will not return nullptr on return_t mismatch. (by design).
96
+ return getMessage_lambda.get_functor <bm::retStr_t>().f_ptr ();
85
97
};
86
98
87
- static auto _test3 = []()
99
+ static auto method_get = [](int n )
88
100
{
89
- if (!getMessageOnNode_lambda.is_signature <bm::argStr_t>() ||
90
- !getMessageOnNode_lambda.is_returning <bm::retStr_t>())
101
+ if (!getMessageOnNode_lambda.is_returning <bm::retStr_t>())
91
102
{
92
- std::cout << " [3] error: signature mismatch.\n " ;
93
- return false ;
103
+ std::cerr << " [3" << n << " ] error: return-type mismatch.\n " ;
104
+ std::abort () ;
94
105
}
95
- return true ;
106
+ // 'get_functor<return_t>': No validation is performed internally and this function
107
+ // will not return nullptr on return_t mismatch. (by design).
108
+ return getMessageOnNode_lambda.get_functor <bm::retStr_t>().f_ptr ();
96
109
};
97
- }
98
110
99
-
100
- void FunctionPointerCall::set (benchmark::State& state)
101
- {
102
- static auto * functor = []() -> void (*)(bm::argStr_t)
103
- {
104
- // Must be checked: Passing an incorrect argument or return type is undefined behaviour.
105
- if (sendMessage_lambda.is_returning <void >() && sendMessage_lambda.is_signature <bm::argStr_t>())
106
- {
107
- // No validation is performed internally and the function will not return nullptr on mismatch.
108
- return sendMessage_lambda.get_functor <void >().f_ptr ();
109
- }
110
- std::cout << " [4] error: signature mismatch.\n " ;
111
- return nullptr ;
112
- }();
113
-
114
- for (auto _ : state)
115
- {
116
- if (functor)
117
- {
118
- (*functor)(bm::g_longStr);
119
- benchmark::DoNotOptimize (bm::g_work_done->c_str ());
120
- }
121
- }
111
+ static auto _new_line = []() {
112
+ std::cout << std::endl;
113
+ return 0 ;
114
+ };
122
115
}
123
116
124
117
125
- void MethodFnPointerCall::set (benchmark::State& state)
126
- {
127
- static bm::Node nodeObj;
128
- static auto functor = []() -> void (bm::Node::*)(bm::argStr_t)
129
- {
130
- // Must be checked: Passing an incorrect argument or return type is undefined behaviour.
131
- if (sendMessageOnNode_lambda.is_returning <void >() && sendMessageOnNode_lambda.is_signature <bm::argStr_t>())
132
- {
133
- // No validation is performed internally and the function will not return nullptr on mismatch.
134
- return sendMessageOnNode_lambda.get_functor <void >().f_ptr ();
135
- }
136
- std::cout << " [8] error: signature mismatch.\n " ;
137
- return nullptr ;
138
- }();
139
118
119
+ void FunctionPointerCall::get (benchmark::State& state)
120
+ {
121
+ static auto functor = functor_get (0 );
140
122
for (auto _ : state)
141
123
{
142
- if (functor)
143
- {
144
- (nodeObj.*functor)(bm::g_longStr);
145
- benchmark::DoNotOptimize (bm::g_work_done->c_str ());
146
- }
124
+ benchmark::DoNotOptimize ((*functor)(bm::g_longStr));
147
125
}
148
126
}
149
127
150
-
151
128
void MethodFnPointerCall::get (benchmark::State& state)
152
129
{
153
130
static bm::Node nodeObj;
154
- static auto functor = []() -> bm::retStr_t (bm::Node::*)(bm::argStr_t)
155
- {
156
- // Must be checked: Passing an incorrect argument or return type is undefined behaviour.
157
- if (getMessageOnNode_lambda.is_returning <bm::retStr_t>() && getMessageOnNode_lambda.is_signature <bm::argStr_t>())
158
- {
159
- // No validation is performed internally and the function will not return nullptr on mismatch.
160
- return getMessageOnNode_lambda.get_functor <bm::retStr_t>().f_ptr ();
161
- }
162
- std::cout << " [9] error: signature mismatch.\n " ;
163
- return nullptr ;
164
- }();
165
-
131
+ static auto functor = method_get (0 );
166
132
for (auto _ : state)
167
133
{
168
- if (functor)
169
- {
170
- benchmark::DoNotOptimize ((nodeObj.*functor)(bm::g_longStr));
171
- }
134
+ benchmark::DoNotOptimize ((nodeObj.*functor)(bm::g_longStr));
172
135
}
173
136
}
174
137
175
-
176
- void FunctionPointerCall::get (benchmark::State& state)
138
+ void FunctionPointerCall::set (benchmark::State& state)
177
139
{
178
- static auto * functor = []() -> bm::retStr_t (*)(bm::argStr_t)
179
- {
180
- // Must be checked: Passing an incorrect argument or return type is undefined behaviour.
181
- if (getMessage_lambda.is_returning <bm::retStr_t>() && getMessage_lambda.is_signature <bm::argStr_t>())
182
- {
183
- // No validation is performed internally and the function will not return nullptr on mismatch.
184
- return getMessage_lambda.get_functor <bm::retStr_t>().f_ptr ();
185
- }
186
- std::cout << " [5] error: signature mismatch.\n " ;
187
- return nullptr ;
188
- }();
189
-
140
+ static auto _ = functor_set (0 );
141
+ static auto functor = sendMessage_lambda.get_functor <void >().f_ptr ();
190
142
for (auto _ : state)
191
143
{
192
- if (functor)
193
- {
194
- benchmark::DoNotOptimize ((*functor)(bm::g_longStr));
195
- }
144
+ (*functor)(bm::g_longStr);
145
+ benchmark::DoNotOptimize (bm::g_work_done->c_str ());
196
146
}
197
147
}
198
148
199
-
200
- void RtlReflectedCall::set (benchmark::State& state)
149
+ void MethodFnPointerCall::set (benchmark::State& state)
201
150
{
202
- static auto passed = _test0 ();
151
+ static bm::Node nodeObj;
152
+ static auto functor = method_set (0 );
203
153
for (auto _ : state)
204
154
{
205
- if (passed)
206
- {
207
- sendMessage_lambda.hop <void >(bm::g_longStr);
208
- benchmark::DoNotOptimize (bm::g_work_done->c_str ());
209
- }
155
+ (nodeObj.*functor)(bm::g_longStr);
156
+ benchmark::DoNotOptimize (bm::g_work_done->c_str ());
210
157
}
211
158
}
212
159
213
160
161
+
214
162
void RtlReflectedCall::get (benchmark::State& state)
215
163
{
216
- static auto passed = _test2 ();
164
+ static auto _=_new_line ();
165
+ static auto _test = functor_get (1 );
217
166
for (auto _: state)
218
167
{
219
- if (passed)
220
- {
221
- benchmark::DoNotOptimize (getMessage_lambda.hop <bm::retStr_t>(bm::g_longStr));
222
- }
168
+ benchmark::DoNotOptimize (getMessage_lambda.hop <bm::retStr_t>(bm::g_longStr));
223
169
}
224
170
}
225
171
226
-
227
- void RtlReflectedMethodCall::set (benchmark::State& state)
172
+ void RtlReflectedMethodCall::get (benchmark::State& state)
228
173
{
229
174
static bm::Node nodeObj;
230
- static auto functor = []() -> void (bm::Node::*)(bm::argStr_t)
231
- {
232
- // Must be checked: Passing an incorrect argument or return type is undefined behaviour.
233
- if (sendMessageOnNode_lambda.is_returning <void >() && sendMessageOnNode_lambda.is_signature <bm::argStr_t>())
234
- {
235
- // No validation is performed internally and the function will not return nullptr on mismatch.
236
- return sendMessageOnNode_lambda.get_functor <void >().f_ptr ();
237
- }
238
- std::cout << " [6] error: signature mismatch.\n " ;
239
- return nullptr ;
240
- }();
241
-
175
+ static auto _test = method_get (1 );
242
176
for (auto _ : state)
243
177
{
244
- if (functor)
245
- {
246
- sendMessageOnNode_lambda.hop <void >(nodeObj, bm::g_longStr);
247
- benchmark::DoNotOptimize (bm::g_work_done->c_str ());
248
- }
178
+ benchmark::DoNotOptimize (getMessageOnNode_lambda.hop <bm::retStr_t>(nodeObj, bm::g_longStr));
249
179
}
250
180
}
251
181
182
+ void RtlReflectedCall::set (benchmark::State& state)
183
+ {
184
+ static auto _=_new_line ();
185
+ static auto _test = functor_set (1 );
186
+ for (auto _ : state)
187
+ {
188
+ sendMessage_lambda.hop <void >(bm::g_longStr);
189
+ benchmark::DoNotOptimize (bm::g_work_done->c_str ());
190
+ }
191
+ }
252
192
253
- void RtlReflectedMethodCall::get (benchmark::State& state)
193
+ void RtlReflectedMethodCall::set (benchmark::State& state)
254
194
{
255
195
static bm::Node nodeObj;
256
- static auto functor = []() -> bm::retStr_t (bm::Node::*)(bm::argStr_t)
257
- {
258
- // Must be checked: Passing an incorrect argument or return type is undefined behaviour.
259
- if (getMessageOnNode_lambda.is_returning <bm::retStr_t>() && getMessageOnNode_lambda.is_signature <bm::argStr_t>())
260
- {
261
- // No validation is performed internally and the function will not return nullptr on mismatch.
262
- return getMessageOnNode_lambda.get_functor <bm::retStr_t>().f_ptr ();
263
- }
264
- std::cout << " [7] error: signature mismatch.\n " ;
265
- return nullptr ;
266
- }();
267
-
196
+ static auto _test = method_set (1 );
268
197
for (auto _ : state)
269
198
{
270
- if (functor)
271
- {
272
- benchmark::DoNotOptimize (getMessageOnNode_lambda.hop <bm::retStr_t>(nodeObj, bm::g_longStr));
273
- }
199
+ sendMessageOnNode_lambda.hop <void >(nodeObj, bm::g_longStr);
200
+ benchmark::DoNotOptimize (bm::g_work_done->c_str ());
274
201
}
275
202
}
0 commit comments