-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCStopWatch.cpp
More file actions
64 lines (53 loc) · 1.05 KB
/
CStopWatch.cpp
File metadata and controls
64 lines (53 loc) · 1.05 KB
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
#include <windows.h>
#include <vector>
#ifndef hr_timer
#include "CStopWatch.h"
#define hr_timer
#endif
double CStopWatch::LIToSecs( LARGE_INTEGER & L) const
{
return ((double)L.QuadPart /(double)frequency.QuadPart);
}
CStopWatch::CStopWatch()
{
resetTimer();
}
void CStopWatch::resetTimer()
{
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency );
}
void CStopWatch::startTimer( )
{
QueryPerformanceCounter(&timer.start);
}
void CStopWatch::stopTimer( )
{
QueryPerformanceCounter(&timer.stop);
}
double CStopWatch::getElapsedTime() const
{
LARGE_INTEGER time;
time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
return LIToSecs( time) ;
}
//CStopWatch w; // for C access.
std::vector<CStopWatch> watches;
int start_stop_watch()
{
static int watchKey = -1;
CStopWatch w;
watchKey++;
watches.push_back(w);
watches[watchKey].startTimer();
return watchKey;
}
void stop_stop_watch(int id)
{
watches[id].stopTimer();
}
double get_duration(int id)
{
return watches[id].getElapsedTime();
}