Thread: QueryPerformanceCounter & Frequency

  1. #1
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476

    QueryPerformanceCounter & Frequency

    Hi, can anybody tell me what do they mean with QueryPerformanceCounter and QueryPerformanceFrequency? And also, what are they implemented for? Thanks in advance.
    Last edited by g4j31a5; 07-20-2008 at 09:55 PM. Reason: Typo
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quotes from MSDN:

    Quote Originally Posted by MSDN
    The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter.
    Quote Originally Posted by MSDN
    The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running.

    lpFrequency
    [out] Pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware does not support a high-resolution performance counter, this parameter can be zero.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    I've read the MSDN but I still can't figure out the use of them in real application. I mean, it's basically similar to the "time.h" functions. So, what are they actually used for? As of now, the only time I use them is in some kind of timeout mechanism. I chose them because I figured it's from Microsoft and I'm programming for Windows so maybe it's better to use it than "time.h". Or maybe I'm wrong. CMIIW.

    EDIT: BTW, I also didn't quite understand the part of MSDN that said: "high-resolution performance counter." It's so vague IMHO.
    Last edited by g4j31a5; 07-21-2008 at 05:31 AM.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It does the same thing as the time.h functions, only they're Windows API and will not work on any other platform.
    They may also have higher precision than time.h, but I cannot say for sure.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Why do you ask? I'm sure there are HUNDREDS of Windows API calls that I've never heard of or used.

    But to answer your question: It gives better precision than clock() or time(). The frequency would be at the very least above 1MHz, it may be as high as GHz. It is also different from clock() in that it counts wallclock time, not CPU time - this may be good or bad, depending on what you want to do.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by matsp View Post
    Why do you ask? I'm sure there are HUNDREDS of Windows API calls that I've never heard of or used.
    --
    Mats
    Well, I'm working on Torque Game Engine right now and I see some calls of the functions in the source code. So I figured maybe I need them if I intend to make my own engine in the future. And I was just curious, that's all. I'm still new in the Windows programming myself.

    Thanks a lot guys.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Windows's buggy clock() actually measures wall time, if I remember correctly.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    Windows's buggy clock() actually measures wall time, if I remember correctly.
    Still? I know DOS used to be that way, but I thought they'd fixed it - oh well, it's been a long time since last time I used clock() to measure anything where background tasks was a measurable percentage of the time anyways.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Determining CPU frequency
    By pgzh in forum Linux Programming
    Replies: 7
    Last Post: 03-17-2008, 10:34 AM
  2. I need to play a pre recorded vox file using C
    By m.sudhakar in forum C Programming
    Replies: 4
    Last Post: 11-17-2006, 06:59 PM
  3. Frequency density of spectrogra[ph/m]
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 12-29-2004, 03:48 AM
  4. Replies: 5
    Last Post: 11-20-2003, 01:27 AM