-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.cpp
65 lines (53 loc) · 1.12 KB
/
timer.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* timer.cpp
* returs elapsed time in micro-sec
*/
#include "timer.h"
#if defined(WIN32)
double CStopWatch::LIToSecs( LARGE_INTEGER & L)
{
return ((double)L.QuadPart /(double)frequency.QuadPart);
}
CStopWatch::CStopWatch()
{
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency );
}
void CStopWatch::startTimer( )
{
QueryPerformanceCounter(&timer.start);
}
void CStopWatch::stopTimer( )
{
QueryPerformanceCounter(&timer.stop);
}
void CStopWatch::refreshTimer( )
{
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency );
}
double CStopWatch::getElapsedTime()
{
LARGE_INTEGER time;
time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
return LIToSecs( time) *1000000;
}
#endif
#if defined(unix)|| defined(__APPLE__)
CStopWatch::CStopWatch(){ }
void CStopWatch::startTimer( )
{
gettimeofday(&start, &tz);
}
void CStopWatch::stopTimer( )
{
gettimeofday(&end, &tz);
}
void CStopWatch::refreshTimer( ) {}
double CStopWatch::getElapsedTime()
{
return time_total=(end.tv_sec-start.tv_sec)*1000000+((double)(end.tv_usec-start.tv_usec));
}
#endif