#ifndef BENCH_INC_UDM_H #define BENCH_INC_UDM_H #include #include #include class GetRusageUDM: public celero::UserDefinedMeasurementTemplate { std::string getName() const override { return "time"; } bool reportSize() const override { return false; } // bool reportMean() const override { return false; } bool reportVariance() const override { return false; } bool reportStandardDeviation() const override { return false; } bool reportSkewness() const override { return false; } bool reportKurtosis() const override { return false; } bool reportZScore() const override { return false; } bool reportMin() const override { return false; } bool reportMax() const override { return false; } }; class GetRusage { int _who; struct rusage _begin, _end; int _iterations; public: explicit GetRusage(int who = RUSAGE_SELF): _who{who} {} void start(int iterations) { _iterations = iterations; getrusage(_who, &_begin); } void stop() { getrusage(_who, &_end); } std::size_t get() { auto begin = _begin.ru_utime, end = _end.ru_utime; auto totalUs = (end.tv_sec - begin.tv_sec) * 1e6 + (end.tv_usec - begin.tv_usec); return totalUs/_iterations; } }; #endif