Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

How to get this queryperformancecounter code to output milliseconds?

This topic is 4974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi heres some code i got from a website, but the problem is it only outputs seconds, and i want milliseconds. How would i get milliseconds?
LARGE_INTEGER freq, count1, count2;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&count1);
QueryPerformanceCounter(&count2);

int overhead = count2.LowPart - count1.LowPart;
QueryPerformanceCounter(&count1);

//
for(int i=0;<i<20000;i++) {
     int a = 3*4*2;
}
//

QueryPerformanceCounter(&count2);
std::cout << "Code took "<< count2.LowPart- count1.LowPart- overhead) / freq.LowPart << " seconds";


Like I don't get how I would get the milliseconds from the line: std::cout << "Code took "<< count2.LowPart- count1.LowPart- overhead) / freq.LowPart << " seconds"; thanks

Share this post


Link to post
Share on other sites
Advertisement
use QueryPerformanceFrequency() to get the number of times per second the counter counts. Then divide the frequency by 1000.
This now tells u how many times per milli second the counter counts.

Then do yer sums.

ace

PS. I could be wrong but don't u use the quadpart of the LARGE_INTEGER.

so time2.quadpart - time1.quadpart.

Share this post


Link to post
Share on other sites
count2.LowPart- count1.LowPart- overhead) / freq.LowPart * 1000

if it gave you seconds, just multiply it by 1000 as i did above since there are 1000 milliseconds in one second.

Share this post


Link to post
Share on other sites
You should use the entire value, not just the lower 32 bits. The QPC frequency on many machines is the CPU frequency. That means that not only can the frequency be too big to fit in 32 bits, but the counter can overflow the lower half in less than a second.

You are doing integer operations which means that (a-b)/f*1000 gives a completely different result from (a-b)*1000/f. (a-b)*1000/f will give you a more accurate result.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!