267 {
268 using namespace asg::msgUserCode;
269
270 auto eventReader = makeEventReader();
272
273 std::vector<ToolData> toolDataVec;
274 for (const auto& testDefinition : testDefinitions)
275 {
276 if (testDefinition.xAODToolCaller != nullptr)
277 {
278 ToolData toolData;
279 toolData.name = testDefinition.name;
280 toolData.xAODToolCaller = testDefinition.xAODToolCaller;
281 toolData.noRepeatCall = testDefinition.noRepeatCall;
282 toolDataVec.push_back(std::move(toolData));
283 }
284 }
285
287 if (!testDefinitions.empty() && testDefinitions[0].tool)
288 evtStore = &*testDefinitions[0].tool->evtStore();
289
290 Benchmark benchmarkEmpty;
291
294 throw std::runtime_error ("ColumnarPhysLiteTest: numberOfEvents == 0");
295 }
296 std::uint64_t
entry = 0;
297
298
299
300
301
302
303 const auto startTime = std::chrono::high_resolution_clock::now();
305 {
306 benchmarkEmpty.startTimer();
307 benchmarkEmpty.stopTimer();
309 if (eventReader->hasClearStore())
310 {
311 static const std::string prepPostfix = "Prep";
312 for (auto& toolData : toolDataVec)
314 for (auto& toolData : toolDataVec)
316 for (auto& toolData : toolDataVec)
318 for (auto& toolData : toolDataVec)
319 toolData.clear (0);
320 eventReader->clearStore();
321 }
322 static const std::string callPostfix = "Call";
323 for (auto& toolData : toolDataVec)
325 for (auto& toolData : toolDataVec)
327 for (auto& toolData : toolDataVec)
328 {
330
331
332
333
334
335 if (userConfiguration.
runToolTwice && !toolData.noRepeatCall)
336 {
338 }
339 }
340 for (auto& toolData : toolDataVec)
341 toolData.clear (1);
342 if (eventReader->hasClearStore())
343 eventReader->clearStore();
344 }
345 std::cout <<
"Total entries read: " <<
entry << std::endl;
346 const float emptyTime = benchmarkEmpty.getEntryTime(0).value();
348 eventReader->printBenchmarkTable(emptyTime);
349
350
351 std::vector<std::pair<ToolPerfData, ToolPerfData>> toolPerfData;
352 for (auto& toolData : toolDataVec)
353 {
355 prepPerfData.
name = toolData.name;
356 if (eventReader->hasClearStore()) {
357 prepPerfData.timeRetrieve = toolData.benchmarkRetrieve[0].getEntryTime(emptyTime);
358 prepPerfData.timeCopyRecord = toolData.benchmarkCopyRecord[0].getEntryTime(emptyTime);
359 prepPerfData.timeCall = toolData.benchmarkCall[0].
getEntryTime(emptyTime);
360 prepPerfData.timeClear = toolData.benchmarkClear[0].getEntryTime(emptyTime);
361 toolData.benchmarkRetrieve[0].setSilence();
362 toolData.benchmarkCopyRecord[0].setSilence();
364 toolData.benchmarkClear[0].setSilence();
365 }
366
368 callPerfData.
name = toolData.name;
369 callPerfData.timeRetrieve = toolData.benchmarkRetrieve[1].getEntryTime(emptyTime);
370 callPerfData.timeCopyRecord = toolData.benchmarkCopyRecord[1].getEntryTime(emptyTime);
371 callPerfData.timeCall = toolData.benchmarkCall[1].
getEntryTime(emptyTime);
372 callPerfData.timeClear = toolData.benchmarkClear[1].getEntryTime(emptyTime);
374 callPerfData.timeCall2 = toolData.benchmarkCall[2].
getEntryTime(emptyTime);
376 }
377 toolData.benchmarkRetrieve[1].setSilence();
378 toolData.benchmarkCopyRecord[1].setSilence();
380 toolData.benchmarkClear[1].setSilence();
381
382 toolPerfData.emplace_back(std::move(prepPerfData), std::move(callPerfData));
383 }
384
385
386 auto printOptionalTime = [](std::optional<float>
time,
int width,
bool trailingBar =
true) {
387 if (time)
388 std::cout << std::format(
"{:>{}.0f}",
time.value(),
width);
389 else
390 std::cout << std::format(
"{:>{}}",
"",
width);
391 if (trailingBar)
392 std::cout << " |";
393 };
394
395
396 std::size_t nameWidth = std::string_view("tool name").size();
397 for (const auto& [prep, call] : toolPerfData)
398 nameWidth = std::max(nameWidth, prep.name.size());
399
400
401 std::string groupHeader = std::format("{:{}} |{:^42}|{:^52}",
402 "", nameWidth, "prep", "call");
403 std::string colHeader = std::format("{:{}} | retr(ns) | copy(ns) | call(ns) | clr(ns) | retr(ns) | copy(ns) | call(ns) | 2nd(ns) | clr(ns)",
404 "tool name", nameWidth);
405
406 std::cout << "\ntool benchmarks:" << std::endl;
407 std::cout << groupHeader << std::endl;
408 std::cout << colHeader << std::endl;
409 std::cout << std::string(colHeader.size(), '-') << std::endl;
410
411
412 for (const auto& [prep, call] : toolPerfData)
413 {
414 std::cout << std::format("{:{}} |", prep.name, nameWidth);
415 printOptionalTime(prep.timeRetrieve, 9);
416 printOptionalTime(prep.timeCopyRecord, 9);
417 printOptionalTime(prep.timeCall, 9);
418 printOptionalTime(prep.timeClear, 8);
419 printOptionalTime(
call.timeRetrieve, 9);
420 printOptionalTime(
call.timeCopyRecord, 9);
421 printOptionalTime(
call.timeCall, 9);
422 printOptionalTime(
call.timeCall2, 8);
423 printOptionalTime(
call.timeClear, 8,
false);
424 std::cout << std::endl;
425 }
426
427
428 if (toolPerfData.size() > 1)
429 {
430 std::optional<float> totalPrepRetrieve, totalPrepCopyRecord, totalPrepCall, totalPrepClear;
431 std::optional<float> totalCallRetrieve, totalCallCopyRecord, totalCallCall, totalCallClear, totalRepeat;
432 for (const auto& [prep, call] : toolPerfData)
433 {
434 if (prep.timeRetrieve)
435 totalPrepRetrieve = totalPrepRetrieve.value_or(0) + prep.timeRetrieve.value();
436 if (prep.timeCopyRecord)
437 totalPrepCopyRecord = totalPrepCopyRecord.value_or(0) + prep.timeCopyRecord.value();
438 if (prep.timeCall)
439 totalPrepCall = totalPrepCall.value_or(0) + prep.timeCall.value();
440 if (prep.timeClear)
441 totalPrepClear = totalPrepClear.value_or(0) + prep.timeClear.value();
442 if (
call.timeRetrieve)
443 totalCallRetrieve = totalCallRetrieve.value_or(0) +
call.timeRetrieve.value();
444 if (
call.timeCopyRecord)
445 totalCallCopyRecord = totalCallCopyRecord.value_or(0) +
call.timeCopyRecord.value();
447 totalCallCall = totalCallCall.value_or(0) +
call.timeCall.value();
449 totalCallClear = totalCallClear.value_or(0) +
call.timeClear.value();
451 totalRepeat = totalRepeat.value_or(0) +
call.timeCall2.value();
452 }
453
454 std::cout << std::string(colHeader.size(), '-') << std::endl;
455 std::cout << std::format("{:{}} |", "total", nameWidth);
456 printOptionalTime(totalPrepRetrieve, 9);
457 printOptionalTime(totalPrepCopyRecord, 9);
458 printOptionalTime(totalPrepCall, 9);
459 printOptionalTime(totalPrepClear, 8);
460 printOptionalTime(totalCallRetrieve, 9);
461 printOptionalTime(totalCallCopyRecord, 9);
462 printOptionalTime(totalCallCall, 9);
463 printOptionalTime(totalRepeat, 8);
464 printOptionalTime(totalCallClear, 8, false);
465 std::cout << std::endl;
466 }
467 }
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)