-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimer.c
More file actions
31 lines (26 loc) · 768 Bytes
/
timer.c
File metadata and controls
31 lines (26 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// simple Timer class, Jan 2010, thomas{AT}thomasfischer{DOT}biz
// tested under windows and linux
// license: do whatever you want to do with it ;)
#include "timer.h"
Timer::Timer() {
restart();
}
double Timer::elapsed() const {
#ifdef WIN32
LARGE_INTEGER tick, ticksPerSecond;
QueryPerformanceFrequency(&ticksPerSecond);
QueryPerformanceCounter(&tick);
return ((double)tick.QuadPart - (double)start.QuadPart) / (double)ticksPerSecond.QuadPart;
#else
struct timeval now;
gettimeofday(&now, (struct timezone *)NULL);
return (now.tv_sec - start.tv_sec) + (now.tv_usec - start.tv_usec)/1000000.0;
#endif
}
void Timer::restart() {
#ifdef WIN32
QueryPerformanceCounter(&start);
#else
gettimeofday(&start, (struct timezone *)NULL);
#endif
}