-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeManager.cpp
More file actions
78 lines (67 loc) · 1.97 KB
/
TimeManager.cpp
File metadata and controls
78 lines (67 loc) · 1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "TimeManager.h"
#include <cstdlib>
TimeManager::TimeManager()
{
#ifdef WIN32
::QueryPerformanceFrequency( &frequency );
m_startCount.QuadPart = 0;
m_endCount.QuadPart = 0;
#else
m_startCount.tv_sec = m_startCount.tv_usec = 0;
m_endCount.tv_sec = m_endCount.tv_usec = 0;
#endif
m_stopped = 0;
m_startTimeInMicroSeconds = 0;
m_endTimeInMicroSeconds = 0;
}
TimeManager::~TimeManager()
{}
void TimeManager::start()
{
m_stopped = 0; // reset stop flag
#ifdef WIN32
::QueryPerformanceCounter( &m_startCount );
#else
gettimeofday( &m_startCount, NULL );
#endif
}
void TimeManager::stop()
{
m_stopped = 1; // set timer stopped flag
#ifdef WIN32
::QueryPerformanceCounter( &m_endCount );
#else
gettimeofday( &m_endCount, NULL );
#endif
}
double TimeManager::getElapsedTimeInMicroseconds()
{
#ifdef WIN32
if(!m_stopped)
{
::QueryPerformanceCounter( &m_endCount );
}
m_startTimeInMicroSec = m_startCount.QuadPart * ( 1000000.0 / m_frequency.QuadPart );
m_endTimeInMicroSec = m_endCount.QuadPart * ( 1000000.0 / m_frequency.QuadPart );
#else
if(!m_stopped)
{
gettimeofday( &m_endCount, NULL );
}
m_startTimeInMicroSeconds = ( m_startCount.tv_sec * 1000000.0 ) + m_startCount.tv_usec;
m_endTimeInMicroSeconds = ( m_endCount.tv_sec * 1000000.0 ) + m_endCount.tv_usec;
#endif
return m_endTimeInMicroSeconds - m_startTimeInMicroSeconds;
}
double TimeManager::getElapsedTimeInMilliseconds()
{
return this->getElapsedTimeInMicroseconds() * 0.001;
}
double TimeManager::getElapsedTimeInSeconds()
{
return this->getElapsedTimeInMicroseconds() * 0.000001;
}
double TimeManager::getElapsedTime()
{
return this->getElapsedTimeInSeconds();
}