Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to calculate running time in microseconds using QueryPerformanceCounter()? please don't give any links answer in this post itself because i have referred many links.
Posted

Hi,

Actually you have to call QueryPerformanceFrequency first.
QueryPerformanceFrequency function will give you ticks/second in your machine. And if QueryPerformanceFrequency function return zero, means your machine not support high resolution performance counter.
Please see following example code:

LARGE_INTEGER t1, t2;
LARGE_INTEGER freq;
LARGE_INTEGER ms;

if( QueryPerformanceFrequency( &freq ) == 0 )
{
printf("Your machine not support high resolution performance counter\n");
return;
}

QueryPerformanceCounter( &t1 );
....
QueryPerformanceCounter( &t2 );

ms = (t2.QuadPart - t1.QuadPart) / (freq.QuadPart / 1000);

ms will have difference between t1 and t2 in milli-seconds.
 
Share this answer
 
Not sure what you mean by 'using QueryPerformanceCounter()' but you can calulate runing time in microseconds as follows
DWORD dwStartTime = GetTickCount();

// do the thing you want to time here

DWORD dwEndTime = GetTickCount();

// calculate the time taken

DWORD dwTimeTaken = (dwEndTime >= dwStartTime) ? dwEndTime - dwStartTime : (0xFFFFFFFF-dwStartTime) + dwEndTime 
// (0xFFFFFFFF-dwStartTime) + dwEndTime  this is incase the tickcount wraps around
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900