Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOSXTimer.cpp
More file actions
Latest commit
60 lines (45 loc) · 1.05 KB
/
Copy pathOSXTimer.cpp
File metadata and controls
60 lines (45 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
#include"Timer.h"
#include<mach/mach.h>
#include<mach/mach_time.h>
classOSXTimer :
public Timer
{
public:
OSXTimer()
:m_startTime(0)
{
//make sure we query the timebase before doing any timing
if (g_firstTime==0)
{
g_firstTime = 1;
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
g_conversion = (1.0 / 1000000000.0) * ((double)timebase.numer / (double)timebase.denom );
}
//start the timer now
m_startTime = mach_absolute_time();
}
staticint g_firstTime;
staticdouble g_conversion;
uint64_t m_startTime;
voidReset()
{
//restart the timer now
m_startTime = mach_absolute_time();
}
doubleGetElapsedTime()
{
//whats the current time?
uint64_t curTime = mach_absolute_time();
uint64_t elapsed = curTime - m_startTime;
return g_conversion * (double)elapsed;
}
virtual~OSXTimer()
{}
};
int OSXTimer::g_firstTime = 0;
double OSXTimer::g_conversion = 0.0;
Timer *Timer::New()
{
returnnewOSXTimer();
}