Hey there, I have this old code im trying to compile using GCC and am running into a few issues..
im trying to figure out how to convert these functions to gcc
static __int64 MyQueryPerformanceFrequency()
{
static __int64 aFreq = 0;
if(aFreq!=0)
return aFreq;
LARGE_INTEGER s1, e1, f1;
__int64 s2, e2, f2;
QueryPerformanceCounter(&s1);
s2 = MyQueryPerformanceCounter();
Sleep(50);
e2 = MyQueryPerformanceCounter();
QueryPerformanceCounter(&e1);
QueryPerformanceFrequency(&f1);
double aTime = (double)(e1.QuadPart - s1.QuadPart)/f1.QuadPart;
f2 = (e2 - s2)/aTime;
aFreq = f2;
return aFreq;
}
void PerfTimer::GlobalStart(const char *theName)
{
gPerfTimerStarted = true;
gPerfTotalTime = 0;
gPerfTimerStartCount = 0;
gPerfElapsedTime = 0;
LARGE_INTEGER anInt; QueryPerformanceCounter(&anInt);
gPerfResetTick = anInt.QuadPart;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void PerfTimer::GlobalStop(const char *theName)
{
LARGE_INTEGER anInt; QueryPerformanceCounter(&anInt);
LARGE_INTEGER aFreq; QueryPerformanceFrequency(&aFreq);
gPerfElapsedTime = (double)(anInt.QuadPart - gPerfResetTick)/aFreq.QuadPart*1000.0;
gPerfTimerStarted = false;
}
I also tried converting this function (original function is the first function below and my converted for gcc function is under that) is this correct?:
#if defined(WIN32)
static __int64 MyQueryPerformanceCounter()
{
// LARGE_INTEGER anInt;
// QueryPerformanceCounter(&anInt);
// return anInt.QuadPart;
#if defined(WIN32)
unsigned long x,y;
_asm
{
rdtsc
mov x, eax
mov y, edx
}
__int64 result = y;
result<<=32;
result|=x;
return result;
}
#else
static __int64 MyQueryPerformanceCounter()
{
struct timeval t1, t2;
double elapsedTime;
// start timer
gettimeofday(&t1, NULL);
Sleep(50);
// stop timer
gettimeofday(&t2, NULL);
// compute and print the elapsed time in millisec
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
return elapsedTime;
}
#endif
Any help would be appreciated, Thank you!
↧