13 #include <valgrind/callgrind.h>
16 #include <framework/logging/Logger.h>
28 namespace TrackFindingCDC {
34 explicit TimeItResult(std::vector<std::chrono::duration<double> >& timeSpans) :
47 std::chrono::duration<double> sumTimeSpan =
50 std::chrono::duration<double> avgTimeSpan = sumTimeSpan /
m_timeSpans.size();
51 return avgTimeSpan.count();
61 B2INFO(
"First execution took " <<
getSeconds(0) <<
" seconds ");
68 std::vector<std::chrono::duration<double> >
m_timeSpans;
73 const std::function<void()> doNothing = []() {};
76 template<
class AFunction >
78 timeIt(
size_t nExecutions,
79 bool activateCallgrind,
80 const AFunction&
function,
81 const std::function<
void()>& setUp = doNothing,
82 const std::function<
void()>& tearDown = doNothing)
84 using namespace std::chrono;
86 std::vector<duration<double>> timeSpans;
87 timeSpans.reserve(nExecutions);
89 for (std::size_t iExecution = 0; iExecution < nExecutions; ++iExecution) {
92 auto now = std::chrono::high_resolution_clock::now();
94 if (activateCallgrind) {
96 CALLGRIND_START_INSTRUMENTATION;
102 if (activateCallgrind) {
104 CALLGRIND_STOP_INSTRUMENTATION;
108 auto later = std::chrono::high_resolution_clock::now();
110 duration<double> timeSpan = duration_cast<duration<double> >(later - now);
111 timeSpans.push_back(timeSpan);