268 {
269 using namespace asg::msgUserCode;
270
271 auto eventReader = makeEventReader();
273
274 std::vector<ToolData> toolDataVec;
275 for (const auto& testDefinition : testDefinitions)
276 {
277 if (testDefinition.xAODToolCaller != nullptr)
278 {
279 ToolData toolData;
280 toolData.name = testDefinition.name;
281 toolData.xAODToolCaller = testDefinition.xAODToolCaller;
282 toolData.noRepeatCall = testDefinition.noRepeatCall;
283 toolDataVec.push_back(std::move(toolData));
284 }
285 }
286
288 if (!testDefinitions.empty() && testDefinitions[0].tool)
289 evtStore = &*testDefinitions[0].tool->evtStore();
290
291 Benchmark benchmarkEmpty;
292
295 throw std::runtime_error ("ColumnarPhysLiteTest: numberOfEvents == 0");
296 }
297 std::uint64_t
entry = 0;
298
299
300
301
302
303
304 const auto startTime = std::chrono::high_resolution_clock::now();
306 {
307 benchmarkEmpty.startTimer();
308 benchmarkEmpty.stopTimer();
310 if (eventReader->hasClearStore())
311 {
312 static const std::string prepPostfix = "Prep";
313 for (auto& toolData : toolDataVec)
315 for (auto& toolData : toolDataVec)
317 for (auto& toolData : toolDataVec)
319 for (auto& toolData : toolDataVec)
320 toolData.clear (0);
321 eventReader->clearStore();
322 }
323 static const std::string callPostfix = "Call";
324 for (auto& toolData : toolDataVec)
326 for (auto& toolData : toolDataVec)
328 for (auto& toolData : toolDataVec)
329 {
331
332
333
334
335
336 if (userConfiguration.
runToolTwice && !toolData.noRepeatCall)
337 {
339 }
340 }
341 for (auto& toolData : toolDataVec)
342 toolData.clear (1);
343 if (eventReader->hasClearStore())
344 eventReader->clearStore();
345 }
346 std::cout <<
"Total entries read: " <<
entry << std::endl;
347 const float emptyTime = benchmarkEmpty.getEntryTime(0).value();
349 eventReader->printBenchmarkTable(emptyTime);
350
351
352 std::vector<std::pair<ToolPerfData, ToolPerfData>> toolPerfData;
353 for (auto& toolData : toolDataVec)
354 {
356 prepPerfData.
name = toolData.name;
357 if (eventReader->hasClearStore()) {
358 prepPerfData.timeRetrieve = toolData.benchmarkRetrieve[0].getEntryTime(emptyTime);
359 prepPerfData.timeCopyRecord = toolData.benchmarkCopyRecord[0].getEntryTime(emptyTime);
360 prepPerfData.timeCall = toolData.benchmarkCall[0].
getEntryTime(emptyTime);
361 prepPerfData.timeClear = toolData.benchmarkClear[0].getEntryTime(emptyTime);
362 toolData.benchmarkRetrieve[0].setSilence();
363 toolData.benchmarkCopyRecord[0].setSilence();
365 toolData.benchmarkClear[0].setSilence();
366 }
367
369 callPerfData.
name = toolData.name;
370 callPerfData.timeRetrieve = toolData.benchmarkRetrieve[1].getEntryTime(emptyTime);
371 callPerfData.timeCopyRecord = toolData.benchmarkCopyRecord[1].getEntryTime(emptyTime);
372 callPerfData.timeCall = toolData.benchmarkCall[1].
getEntryTime(emptyTime);
373 callPerfData.timeClear = toolData.benchmarkClear[1].getEntryTime(emptyTime);
375 callPerfData.timeCall2 = toolData.benchmarkCall[2].
getEntryTime(emptyTime);
377 }
378 toolData.benchmarkRetrieve[1].setSilence();
379 toolData.benchmarkCopyRecord[1].setSilence();
381 toolData.benchmarkClear[1].setSilence();
382
383 toolPerfData.emplace_back(std::move(prepPerfData), std::move(callPerfData));
384 }
385
386
387 auto printOptionalTime = [](std::optional<float>
time,
int width,
bool trailingBar =
true) {
388 if (time)
389 std::cout << std::format(
"{:>{}.0f}",
time.value(),
width);
390 else
391 std::cout << std::format(
"{:>{}}",
"",
width);
392 if (trailingBar)
393 std::cout << " |";
394 };
395
396
397 std::size_t nameWidth = std::string_view("tool name").size();
398 for (const auto& [prep, call] : toolPerfData)
399 nameWidth = std::max(nameWidth, prep.name.size());
400
401
402 std::string groupHeader = std::format("{:{}} |{:^42}|{:^52}",
403 "", nameWidth, "prep", "call");
404 std::string colHeader = std::format("{:{}} | retr(ns) | copy(ns) | call(ns) | clr(ns) | retr(ns) | copy(ns) | call(ns) | 2nd(ns) | clr(ns)",
405 "tool name", nameWidth);
406
407 std::cout << "\ntool benchmarks:" << std::endl;
408 std::cout << groupHeader << std::endl;
409 std::cout << colHeader << std::endl;
410 std::cout << std::string(colHeader.size(), '-') << std::endl;
411
412
413 for (const auto& [prep, call] : toolPerfData)
414 {
415 std::cout << std::format("{:{}} |", prep.name, nameWidth);
416 printOptionalTime(prep.timeRetrieve, 9);
417 printOptionalTime(prep.timeCopyRecord, 9);
418 printOptionalTime(prep.timeCall, 9);
419 printOptionalTime(prep.timeClear, 8);
420 printOptionalTime(
call.timeRetrieve, 9);
421 printOptionalTime(
call.timeCopyRecord, 9);
422 printOptionalTime(
call.timeCall, 9);
423 printOptionalTime(
call.timeCall2, 8);
424 printOptionalTime(
call.timeClear, 8,
false);
425 std::cout << std::endl;
426 }
427
428
429 if (toolPerfData.size() > 1)
430 {
431 std::optional<float> totalPrepRetrieve, totalPrepCopyRecord, totalPrepCall, totalPrepClear;
432 std::optional<float> totalCallRetrieve, totalCallCopyRecord, totalCallCall, totalCallClear, totalRepeat;
433 for (const auto& [prep, call] : toolPerfData)
434 {
435 if (prep.timeRetrieve)
436 totalPrepRetrieve = totalPrepRetrieve.value_or(0) + prep.timeRetrieve.value();
437 if (prep.timeCopyRecord)
438 totalPrepCopyRecord = totalPrepCopyRecord.value_or(0) + prep.timeCopyRecord.value();
439 if (prep.timeCall)
440 totalPrepCall = totalPrepCall.value_or(0) + prep.timeCall.value();
441 if (prep.timeClear)
442 totalPrepClear = totalPrepClear.value_or(0) + prep.timeClear.value();
443 if (
call.timeRetrieve)
444 totalCallRetrieve = totalCallRetrieve.value_or(0) +
call.timeRetrieve.value();
445 if (
call.timeCopyRecord)
446 totalCallCopyRecord = totalCallCopyRecord.value_or(0) +
call.timeCopyRecord.value();
448 totalCallCall = totalCallCall.value_or(0) +
call.timeCall.value();
450 totalCallClear = totalCallClear.value_or(0) +
call.timeClear.value();
452 totalRepeat = totalRepeat.value_or(0) +
call.timeCall2.value();
453 }
454
455 std::cout << std::string(colHeader.size(), '-') << std::endl;
456 std::cout << std::format("{:{}} |", "total", nameWidth);
457 printOptionalTime(totalPrepRetrieve, 9);
458 printOptionalTime(totalPrepCopyRecord, 9);
459 printOptionalTime(totalPrepCall, 9);
460 printOptionalTime(totalPrepClear, 8);
461 printOptionalTime(totalCallRetrieve, 9);
462 printOptionalTime(totalCallCopyRecord, 9);
463 printOptionalTime(totalCallCall, 9);
464 printOptionalTime(totalRepeat, 8);
465 printOptionalTime(totalCallClear, 8, false);
466 std::cout << std::endl;
467 }
468 }
std::optional< float > getEntryTime(float emptyTime) const
time(flags, cells_name, *args, **kw)
call(args, bufsize=0, executable=None, stdin=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, message="", logger=msg, loglevel=None, timeout=None, retry=2, timefactor=1.5, sleeptime=10)