5#ifndef __pinocchio_utils_timer_hpp__
6#define __pinocchio_utils_timer_hpp__
12int 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) / 10000000L);
29 tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
38#define SMOOTH(s) for (size_t _smooth = 0; _smooth < s; ++_smooth)
41inline 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);
58 static std::string unitName(Unit u)
74 std::stack<struct timeval> stack;
75 mutable struct timeval t0;
85 gettimeofday(&(stack.top()), NULL);
90 return toc(DEFAULT_UNIT);
93 inline double toc(
const Unit factor)
95 gettimeofday(&t0, NULL);
96 double dt = (t0 - stack.top()) * (
double)factor;
101 inline void toc(std::ostream & os,
double SMOOTH = 1)
103 os << toc(DEFAULT_UNIT) / SMOOTH <<
" " << unitName(DEFAULT_UNIT) << std::endl;