@@ -85,12 +85,8 @@ bool Parse(int argc, char** argv, BenchmarkConfig& config)
85
85
std::vector<std::string> args;
86
86
std::copy ((argv + 1 ), (argv + argc), std::back_inserter (args));
87
87
88
- auto asNum = [](const auto & str) {
89
- return static_cast <uint32_t >(std::stoul (str));
90
- };
91
- auto asStr = [](auto & a) {
92
- return std::string{a};
93
- };
88
+ auto asNum = [](const auto & str) { return static_cast <uint32_t >(std::stoul (str)); };
89
+ auto asStr = [](auto & a) { return std::string{a}; };
94
90
95
91
// test and remove the flag from args, returns true if flag was present
96
92
auto consumeFlag = [&args](const auto & namedOption) {
@@ -188,7 +184,9 @@ bool Parse(int argc, char** argv, BenchmarkConfig& config)
188
184
case 2 :
189
185
config.messageSizeInBytes = asNum (args.at (1 ));
190
186
// [[fallthrough]]
191
- case 1 : config.messageCount = asNum (args.at (0 )); break ;
187
+ case 1 :
188
+ config.messageCount = asNum (args.at (0 ));
189
+ break ;
192
190
default :
193
191
if (haveUserOptions)
194
192
{
@@ -245,7 +243,8 @@ void PrintParameters(BenchmarkConfig benchmark)
245
243
<< std::endl
246
244
<< " Running simulations with the following parameters:" << std::endl
247
245
<< std::endl
248
- << std::left << std::setw (38 ) << " - Is Receiver: " << (benchmark.isReceiver ? " True" : " False" ) << std::endl
246
+ << std::left << std::setw (38 ) << " - Is Receiver: " << (benchmark.isReceiver ? " True" : " False" )
247
+ << std::endl
249
248
<< std::left << std::setw (38 ) << " - Total message count: " << benchmark.messageCount << std::endl
250
249
<< std::left << std::setw (38 ) << " - Message size (bytes): " << benchmark.messageSizeInBytes << std::endl
251
250
<< std::left << std::setw (38 ) << " - Registry URI: " << benchmark.registryUri << std::endl
@@ -315,38 +314,39 @@ int main(int argc, char** argv)
315
314
std::string topicPub = benchmark.isReceiver ? " Pong" : " Ping" ;
316
315
std::string topicSub = benchmark.isReceiver ? " Ping" : " Pong" ;
317
316
auto publisher = participant->CreateDataPublisher (" PubCtrl1" , {topicPub, {}}, 1 );
318
- participant->CreateDataSubscriber (
319
- " SubCtrl1" , {topicSub, {}},
320
- [data, publisher, benchmark, &sendCount, &allSent, &allSentPromise,
317
+ participant->CreateDataSubscriber (" SubCtrl1" , {topicSub, {}},
318
+ [data, publisher, benchmark, &sendCount, &allSent, &allSentPromise,
321
319
322
- &measuredRoundtrips, &sendTime, &startTimestamp](auto *, auto &) {
323
- if (!allSent)
320
+ &measuredRoundtrips, &sendTime, &startTimestamp](auto *, auto &) {
321
+ if (!allSent)
322
+ {
323
+ if (!benchmark.isReceiver )
324
324
{
325
- if (!benchmark. isReceiver )
325
+ if (sendCount == 0 )
326
326
{
327
- if (sendCount == 0 )
328
- {
329
- startTimestamp = std::chrono::high_resolution_clock::now (); // Initial receive: Start runtime measurement
330
- }
331
- else
332
- {
333
- measuredRoundtrips.push_back (std::chrono::high_resolution_clock::now () - sendTime);
334
- }
335
- sendTime = std::chrono::high_resolution_clock::now ();
327
+ startTimestamp =
328
+ std::chrono::high_resolution_clock::now (); // Initial receive: Start runtime measurement
336
329
}
337
- publisher->Publish (data);
338
- sendCount++;
339
- if (benchmark.isReceiver && (benchmark.messageCount <= 20 || sendCount % (benchmark.messageCount / 20 ) == 0 ))
330
+ else
340
331
{
341
- std::cout << " ." ;
342
- }
343
- if (sendCount >= benchmark.messageCount +1 ) // Initial publish has no timing, use +1
344
- {
345
- allSentPromise.set_value ();
346
- allSent = true ;
332
+ measuredRoundtrips.push_back (std::chrono::high_resolution_clock::now () - sendTime);
347
333
}
334
+ sendTime = std::chrono::high_resolution_clock::now ();
335
+ }
336
+ publisher->Publish (data);
337
+ sendCount++;
338
+ if (benchmark.isReceiver
339
+ && (benchmark.messageCount <= 20 || sendCount % (benchmark.messageCount / 20 ) == 0 ))
340
+ {
341
+ std::cout << " ." ;
348
342
}
349
- });
343
+ if (sendCount >= benchmark.messageCount + 1 ) // Initial publish has no timing, use +1
344
+ {
345
+ allSentPromise.set_value ();
346
+ allSent = true ;
347
+ }
348
+ }
349
+ });
350
350
351
351
if (!benchmark.isReceiver ) // Initial publish without timing
352
352
{
@@ -371,13 +371,13 @@ int main(int argc, char** argv)
371
371
allDonePublisher->Publish (std::vector<uint8_t >{0 });
372
372
}
373
373
participant->CreateDataSubscriber (" SubCtrl2" , {topicSubAllDone, {}},
374
- [&syncParticipants, benchmark, allDonePublisher](auto *, auto &) {
375
- if (!benchmark.isReceiver )
376
- {
377
- allDonePublisher->Publish (std::vector<uint8_t >{0 });
378
- }
379
- syncParticipants.set_value ();
380
- });
374
+ [&syncParticipants, benchmark, allDonePublisher](auto *, auto &) {
375
+ if (!benchmark.isReceiver )
376
+ {
377
+ allDonePublisher->Publish (std::vector<uint8_t >{0 });
378
+ }
379
+ syncParticipants.set_value ();
380
+ });
381
381
auto syncParticipantsFuture = syncParticipants.get_future ();
382
382
syncParticipantsFuture.wait ();
383
383
std::cout << " ... done." << std::endl;
@@ -394,8 +394,9 @@ int main(int argc, char** argv)
394
394
std::vector<double > measuredLatencySeconds (measuredRoundtrips.size ());
395
395
std::transform (measuredRoundtrips.begin (), measuredRoundtrips.end (), measuredLatencySeconds.begin (),
396
396
[](auto d) {
397
- return static_cast <double >(d.count () / 1 .e3 * 0.5 ); // Convert to microseconds, factor 0.5 for latency from roundtrip
398
- });
397
+ return static_cast <double >(d.count () / 1 .e3
398
+ * 0.5 ); // Convert to microseconds, factor 0.5 for latency from roundtrip
399
+ });
399
400
400
401
const auto averageLatency = mean_and_error (measuredLatencySeconds);
401
402
std::ostringstream averageLatencyWithUnit;
@@ -417,16 +418,20 @@ int main(int argc, char** argv)
417
418
durationWithUnit.precision (3 );
418
419
durationWithUnit << durationSeconds << " s" ;
419
420
420
- std::cout << std::setw (38 ) << " - Realtime duration (runtime): " << std::setw (6 ) << durationWithUnit.str () << std::endl
421
- << std::setw (38 ) << " - Throughput (data size/runtime): " << std::setw (6 ) << throughputWithUnit.str () << std::endl
422
- << std::setw (38 ) << " - Latency: " << std::setw (6 ) << averageLatencyWithUnit.str () << " +/- " << averageLatency.second << std::endl
421
+ std::cout << std::setw (38 ) << " - Realtime duration (runtime): " << std::setw (6 ) << durationWithUnit.str ()
422
+ << std::endl
423
+ << std::setw (38 ) << " - Throughput (data size/runtime): " << std::setw (6 ) << throughputWithUnit.str ()
424
+ << std::endl
425
+ << std::setw (38 ) << " - Latency: " << std::setw (6 ) << averageLatencyWithUnit.str () << " +/- "
426
+ << averageLatency.second << std::endl
423
427
<< std::endl;
424
428
425
429
if (benchmark.writeCsv != " " )
426
430
{
427
431
std::stringstream csvHeader;
428
432
csvHeader << " # SilKitBenchmarkDemo, SIL Kit Version " << SilKit::Version::String ();
429
- const auto csvColumns = " messageSize; messageCount; runtime(s); throughput(MiB/s); latency(us); latency_err" ;
433
+ const auto csvColumns =
434
+ " messageSize; messageCount; runtime(s); throughput(MiB/s); latency(us); latency_err" ;
430
435
std::fstream csvFile;
431
436
csvFile.open (benchmark.writeCsv , std::ios_base::in | std::ios_base::out); // Try to open
432
437
bool csvValid{true };
@@ -453,10 +458,9 @@ int main(int argc, char** argv)
453
458
{
454
459
// Append data
455
460
csvFile.seekp (0 , std::ios_base::end);
456
- csvFile << benchmark.messageSizeInBytes << " ;" << benchmark.messageCount << " ;"
457
- << durationSeconds << " ;"
458
- << throughput << " ;"
459
- << averageLatency.first << " ;" << averageLatency.second << std::endl;
461
+ csvFile << benchmark.messageSizeInBytes << " ;" << benchmark.messageCount << " ;" << durationSeconds
462
+ << " ;" << throughput << " ;" << averageLatency.first << " ;" << averageLatency.second
463
+ << std::endl;
460
464
}
461
465
csvFile.close ();
462
466
}
0 commit comments