alsk/celero/inc/udm.h

41 lines
1.2 KiB
C++

#ifndef BENCH_INC_UDM_H
#define BENCH_INC_UDM_H
#include <celero/Celero.h>
#include <sys/time.h>
#include <sys/resource.h>
class GetRusageUDM: public celero::UserDefinedMeasurementTemplate<std::size_t> {
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