6#include "metrics/hart_metrics_common.hpp"
64#define HART_TIME_IT(timeItInstanceName, numRuns)
65 ::hart::TimeIt timeItInstanceName (numRuns);
66 for (size_t HART_timeItCurrentRun = 0
; HART_timeItCurrentRun < (numRuns); ++HART_timeItCurrentRun)
67 for (bool HART_timeItRunOnce = true; HART_timeItRunOnce; HART_timeItRunOnce = false)
68 for (::hart::TimeItSample HART_sample (timeItInstanceName); HART_timeItRunOnce; HART_timeItRunOnce = false)
80 m_observedDurationsSeconds.reserve (numRuns);
86 void add (
double durationSeconds)
88 m_observedDurationsSeconds.push_back (durationSeconds);
97 template <
typename ReducerType>
98 auto result (ReducerType&& reducer)
const
99 -> ReducerResultType<ReducerType, std::vector<
double>::const_iterator>
101 return reducer (m_observedDurationsSeconds.begin(), m_observedDurationsSeconds.end());
105 std::vector<
double> m_observedDurationsSeconds;
112 using clock = std::chrono::steady_clock;
115 clock::time_point m_start;
117 explicit TimeItSample (
TimeIt& timeIt) :
119 m_start (clock::now())
123 TimeItSample (
const TimeItSample&) =
delete;
124 TimeItSample (TimeItSample&&) =
delete;
125 TimeItSample& operator= (
const TimeItSample&) =
delete;
126 TimeItSample& operator= (TimeItSample&&) =
delete;
130 const clock::time_point end = clock::now();
132 using std::chrono::duration_cast;
133 using DurationDoubleType = std::chrono::duration<
double>;
134 const double durationSeconds = duration_cast<DurationDoubleType> (end - m_start).count();
136 m_timeIt.add (durationSeconds);
Helper class for measuring duration of some block of code over multiple runs.
TimeIt(size_t numRuns)
Creates a new TimeIt instance.
auto result(ReducerType &&reducer) const -> ReducerResultType< ReducerType, std::vector< double >::const_iterator >
Get the result of the timing measurement.