-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathtimer.cpp
More file actions
47 lines (35 loc) · 876 Bytes
/
Copy pathtimer.cpp
File metadata and controls
47 lines (35 loc) · 876 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "timer.h"
#ifdef __GNUC__
#include <cstdio>
#include <sys/time.h>
struct timeval start, stop;
void start_timer(void)
{
gettimeofday(&start, NULL);
}
long long stop_timer_us(void)
{
gettimeofday(&stop, NULL);
long long rv;
rv = (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec;
return rv;
}
#else
#include <Windows.h>
#include <profileapi.h>
LARGE_INTEGER StartingTime, EndingTime, ElapsedMicroseconds;
LARGE_INTEGER Frequency;
void start_timer(void)
{
QueryPerformanceCounter(&StartingTime);
}
long long stop_timer_us(void)
{
LARGE_INTEGER EndingTime;
QueryPerformanceCounter(&EndingTime);
LARGE_INTEGER ElapsedMicroseconds;
ElapsedMicroseconds.QuadPart = EndingTime.QuadPart - StartingTime.QuadPart;
long long rv = (long long)ElapsedMicroseconds.QuadPart;
return rv;
}
#endif // WIN32