tagging release
[dasher.git] / Src / DasherCore / SimpleTimer.cpp
blobb7ac1b8e4f6f1fba08c665adea00d264aea145d5
2 #include "../Common/Common.h"
4 #include "SimpleTimer.h"
6 #ifdef _WIN32
7 #include <sys/timeb.h>
8 #else
9 #include <sys/time.h>
10 #endif
12 // Track memory leaks on Windows to the line that new'd the memory
13 #ifdef _WIN32
14 #ifdef _DEBUG
15 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
16 #define new DEBUG_NEW
17 #undef THIS_FILE
18 static char THIS_FILE[] = __FILE__;
19 #endif
20 #endif
22 CSimpleTimer::CSimpleTimer()
24 #ifdef _WIN32
25 struct timeb sTimeBuffer;
26 #else
27 struct timeval sTimeBuffer;
28 struct timezone sTimezoneBuffer;
29 #endif
31 #ifdef _WIN32
32 ftime(&sTimeBuffer);
33 m_iStartMs = sTimeBuffer.millitm;
34 m_iStartSecond = sTimeBuffer.time;
35 #else
36 gettimeofday(&sTimeBuffer, &sTimezoneBuffer);
37 m_iStartMs = sTimeBuffer.tv_usec / 1000;
38 m_iStartSecond = sTimeBuffer.tv_sec;
39 #endif
43 CSimpleTimer::~CSimpleTimer()
47 double CSimpleTimer::GetElapsed()
49 #ifdef _WIN32
50 struct timeb sTimeBuffer;
51 #else
52 struct timeval sTimeBuffer;
53 struct timezone sTimezoneBuffer;
54 #endif
56 #ifdef _WIN32
57 ftime(&sTimeBuffer);
58 int iEndMs = sTimeBuffer.millitm;
59 int iEndSecond = sTimeBuffer.time;
60 #else
61 gettimeofday(&sTimeBuffer, &sTimezoneBuffer);
62 int iEndMs = sTimeBuffer.tv_usec / 1000;
63 int iEndSecond = sTimeBuffer.tv_sec;
64 #endif
67 return ((double) iEndMs / 1000.0 + (double) iEndSecond) -
68 ((double) m_iStartMs / 1000.0 + (double) m_iStartSecond);