jes/src/core/Timer.cc
2016-07-10 20:42:38 -04:00

32 lines
437 B
C++

#include "Timer.h"
#include <sys/time.h>
#include <stdio.h>
static long get_usec()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}
Timer::Timer()
{
m_start_time = 0;
m_elapsed = 0;
}
void Timer::start()
{
m_start_time = get_usec();
}
void Timer::stop()
{
m_elapsed = get_usec() - m_start_time;
}
void Timer::print()
{
printf("Elapsed: %ldus\n", m_elapsed);
}