CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: elapsed time in microseconds, VC++

  1. #1
    Join Date
    Jun 2007
    Posts
    1

    Exclamation elapsed time in microseconds, VC++

    Hi

    I'm using VC++ Express, im trying to get elapsed time in microseconds
    for consol app. . i tryed the clock function but it didn't show the time in microseconds.

  2. #2
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: elapsed time in microseconds, VC++

    Well, Windows is not a Real Time Operating System.... Even when you manage to get the elapsed time in microseconds, you will not get the accuracy you are looking for.

    You can use GetTickCount API to get time elapsed in msecs. Another option is the Timer Classes in this FAQ to get results as well.

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: elapsed time in microseconds, VC++

    Siddhartha is right. Any numbers you tried to get would be meaningless.

    But:
    Code:
    double uS = (clock() / CLKS_PER_SEC) * 1000000;
    Will give that numeric quantity...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: elapsed time in microseconds, VC++

    Hello,

    GetTickCount and timers will not be of help, if you want to measure time between events to an accuracy of microsec. GetTickCount function have an accuracy of millisec only. Timers have low priority. What you have to use is the high resolution performance counter.

    The FAQ How do I evaluate the time difference between two events? may be helpful.

    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: elapsed time in microseconds, VC++

    Quote Originally Posted by Pravin Kumar
    Hello,

    GetTickCount and timers will not be of help, if you want to measure time between events to an accuracy of microsec. GetTickCount function have an accuracy of millisec only. Timers have low priority. What you have to use is the high resolution performance counter.

    The FAQ How do I evaluate the time difference between two events? may be helpful.

    Regards,
    Pravin.
    Which is exactly what we have all been saying. However there are a few (albiet almost all ill-concieved) where it is desired to express a measurement in units that are not appropriate, but are mathematically valid.

    For example.

    X occurs once a day +/- 10 minutes.

    X occurs every 86400000000uS +/- 600000000uS

    Both are equally valid from every point of view. But the first "makes more sense".
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: elapsed time in microseconds, VC++

    Quote Originally Posted by Pravin Kumar
    timers will not be of help

    [...]

    The FAQ How do I evaluate the time difference between two events? may be helpful.
    Pravin, the timer class in the FAQ presented above does exactly what your FAQ does (QueryPerformance* APIs).
    Last edited by Siddhartha; June 7th, 2007 at 03:53 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)