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
|
#include "../Common/Common.h"
#include "SimpleTimer.h"
#ifdef _WIN32
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif
// Track memory leaks on Windows to the line that new'd the memory
#ifdef _WIN32
#ifdef _DEBUG
#define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#endif
CSimpleTimer::CSimpleTimer()
{
#ifdef _WIN32
struct timeb sTimeBuffer;
#else
struct timeval sTimeBuffer;
struct timezone sTimezoneBuffer;
#endif
#ifdef _WIN32
ftime(&sTimeBuffer);
m_iStartMs = sTimeBuffer.millitm;
m_iStartSecond = sTimeBuffer.time;
#else
gettimeofday(&sTimeBuffer, &sTimezoneBuffer);
m_iStartMs = (int)sTimeBuffer.tv_usec / 1000;
m_iStartSecond = (int)sTimeBuffer.tv_sec;
#endif
}
CSimpleTimer::~CSimpleTimer()
{
}
double CSimpleTimer::GetElapsed()
{
#ifdef _WIN32
struct timeb sTimeBuffer;
#else
struct timeval sTimeBuffer;
struct timezone sTimezoneBuffer;
#endif
#ifdef _WIN32
ftime(&sTimeBuffer);
int iEndMs = sTimeBuffer.millitm;
int iEndSecond = sTimeBuffer.time;
#else
gettimeofday(&sTimeBuffer, &sTimezoneBuffer);
int iEndMs = (int)sTimeBuffer.tv_usec / 1000;
int iEndSecond = (int)sTimeBuffer.tv_sec;
#endif
return ((double) iEndMs / 1000.0 + (double) iEndSecond) -
((double) m_iStartMs / 1000.0 + (double) m_iStartSecond);
}
|