add Timer

This commit is contained in:
josh committed 2016-07-10 20:42:38 -04:00
1 parent b1684f1341
commit dd7a5de619
2 files changed
+50

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
#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);
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef TIMER_H
#define TIMER_H
class Timer
{
public:
Timer();
void start();
void stop();
void print();
long get_elapsed() { return m_elapsed; }
protected:
long m_start_time;
long m_elapsed;
};
#endif