×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

timeGetTime vs. QueryPerformanceCounter

timeGetTime vs. QueryPerformanceCounter

timeGetTime vs. QueryPerformanceCounter

(OP)
Something I was curious about as I was trying to get some good program timing code working:

I notice these two values aren't anywhere in sync in terms of what the numbers are.  (This is after I take QPC / (QPF / 1000) of course.)  I was wondering if anyone knew the difference between the two numbers and where they came from.

Is QPC/QPF somehow hardware dependent compared to timeGetTime being software?  Or is there some other explanation?

RE: timeGetTime vs. QueryPerformanceCounter

What's a problem?
1. Yes, QPF returned value is hardware dependent (but it's not a CPU frequency!).
2. timeGetTime has 1 millisecond precision by default (too low;).
3. To obtain short time interval(s) by QPF/QPC calls:

CODE

#include <windows.h>
...
LARGE_INTEGER
  f,  /* HPC ticks per second */
  t0, /* start counter */
  t1; /* end counter value */
double micros; // want in microseconds, see 1e6 constant
...
if (QueryPerformanceFrequency(&f))
{
   printf("Performance Frequency is %d\n",(int)f.QuadPart);
   if (QueryPerformanceCounter(&t0))
   {
      /* ** tested code here ** */
      if (QueryPerformanceCounter(&t1))
      {
         micros = (double)(t1.QuadPart - t0.QuadPart) * 1e6
                  /
                  (double)x.QuadPart;
         printf("Elapse time is %g microseconds\n",micros);
      }
   }
}
else
   printf("*** QPF failed.\n");
...

RE: timeGetTime vs. QueryPerformanceCounter

Sorry, must be (double)f.QuadPart divider...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close