2006-04-24 01:14:18 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "HighResTimer.h"
|
|
|
|
|
2006-12-01 21:34:28 +01:00
|
|
|
// TODO: Better accuracy and reliability, if necessary.
|
2006-11-12 05:02:36 +01:00
|
|
|
|
2006-12-01 21:34:28 +01:00
|
|
|
#ifdef __WXMSW__
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
HighResTimer::HighResTimer()
|
|
|
|
{
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
BOOL ok = QueryPerformanceFrequency(&freq);
|
|
|
|
if (! ok)
|
|
|
|
{
|
|
|
|
wxLogError(_("QPF failed!"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_TickLength = freq.QuadPart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double HighResTimer::GetTime()
|
|
|
|
{
|
|
|
|
LARGE_INTEGER count;
|
|
|
|
BOOL ok = QueryPerformanceCounter(&count);
|
|
|
|
if (! ok)
|
|
|
|
{
|
|
|
|
wxLogError(_("QPC failed!"));
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
return (double)count.QuadPart / (double)m_TickLength.GetValue();
|
2006-12-01 21:34:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // not __WXMSW__ :
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
HighResTimer::HighResTimer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double HighResTimer::GetTime()
|
|
|
|
{
|
2006-11-12 05:02:36 +01:00
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_sec+(tv.tv_usec/1000000.0);
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
2006-12-01 21:34:28 +01:00
|
|
|
|
|
|
|
#endif
|