75 inline void start() { gettimeofday(&start_time_, NULL); }
85 gettimeofday(¤t_time, NULL);
89 (double)(current_time.tv_sec - start_time_.tv_sec) +
90 ((double)(current_time.tv_usec - start_time_.tv_usec))/1.0E6;
108 gettimeofday(¤t_time, NULL);
110 (double)current_time.tv_sec + ((
double)current_time.tv_usec)/1.0E6;
120 gettimeofday(¤t_time, NULL);
122 (size_t)current_time.tv_sec * 1000000 + (
size_t)current_time.tv_usec;
158 static void sleep(
size_t sleeplen);
163 static void sleep_ms(
size_t sleeplen);
166 typedef unsigned long long rdtsc_type;
174 #if defined(__i386__) 179 inline rdtsc_type
rdtsc(
void) {
180 unsigned long long int x;
181 __asm__
volatile (
".byte 0x0f, 0x31" :
"=A" (x));
184 #elif defined(__x86_64__) 189 inline rdtsc_type
rdtsc(
void) {
191 __asm__ __volatile__ (
"rdtsc" :
"=a"(lo),
"=d"(hi));
192 return ( (
unsigned long long)lo) | ( ((
unsigned long long)hi)<<32 );
230 rdtsc_type end =
rdtsc();
231 double dtime = end - begin;
246 std::ostream& operator<<(std::ostream& out,
const turi::timer& t);
double current_time_millis() const
Returns the elapsed time in milliseconds since turi::timer::start was last called.
void start()
Reset the timer.
static void sleep_ms(size_t sleeplen)
static size_t approx_time_millis()
Returns the time since program start.
static double sec_of_day()
Get the number of seconds (as a floating point value) since the Unix Epoch.
static float approx_time_seconds()
Returns the time since program start.
static size_t usec_of_day()
Returns only the micro-second component of the time since the Unix Epoch.
rdtsc_type estimate_ticks_per_second()
double current_time() const
Returns the elapsed time in seconds since turi::timer::start was last called.
static void stop_approx_timer()
Stops the approximate timer.
timer()
The timer starts on construction but can be restarted by calling turi::timer::start.
A simple class that can be used for benchmarking/timing up to microsecond resolution.
static void sleep(size_t sleeplen)