5 #ifndef __pinocchio_utils_timer_hpp__ 6 #define __pinocchio_utils_timer_hpp__ 12 int gettimeofday(
struct timeval* tp,
struct timezone* tzp)
17 static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
19 SYSTEMTIME system_time;
23 GetSystemTime(&system_time);
24 SystemTimeToFileTime(&system_time, &file_time);
25 time = ((uint64_t)file_time.dwLowDateTime);
26 time += ((uint64_t)file_time.dwHighDateTime) << 32;
28 tp->tv_sec = (long)((time - EPOCH) / 10000000
L);
29 tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
38 #define SMOOTH(s) for(size_t _smooth=0;_smooth<s;++_smooth) 41 inline double operator-(
const struct timeval & t1,
const struct timeval & t0)
44 return double(t1.tv_sec - t0.tv_sec)+1e-6*double(t1.tv_usec - t0.tv_usec);
49 enum Unit {
S = 1,
MS = 1000,
US = 1000000,
NS = 1000000000 };
54 switch(u) {
case S:
return "s";
case MS:
return "ms";
case US:
return "us";
case NS:
return "ns"; }
58 std::stack<struct timeval>
stack;
59 mutable struct timeval
t0;
65 gettimeofday(&(stack.top()),NULL);
68 inline double toc() {
return toc(DEFAULT_UNIT); };
72 gettimeofday(&
t0,NULL);
73 double dt = (
t0-stack.top())*(
double)factor;
84 #endif // ifndef __pinocchio_utils_timer_hpp__
static std::string unitName(Unit u)
double operator-(const struct timeval &t1, const struct timeval &t0)
void def(const char *name, Func func)
PinocchioTicToc(Unit def=MS)
void toc(std::ostream &os, double SMOOTH=1)
std::stack< struct timeval > stack
double toc(const Unit factor)