none
Getting Time in Milliseconds in Visual C++

    Question

  • Hi,

    Is there any way of getting time taken by a function in Visual C++ 2008 ? I am using time_t but that's giving me the answer in seconds.

    Thanks

    Amare

    Tuesday, May 18, 2010 7:04 AM

Answers

  • Use GetTickCount
    Nikita Leontiev
    • Marked as answer by Amare1982 Wednesday, May 19, 2010 3:24 AM
    Tuesday, May 18, 2010 7:29 AM
  • > Is there any way of getting time taken by a function in Visual C++ 2008
    > ? I am using time_t but that's giving me the answer in seconds.
     
    For high precision timing, have a look at using the
    QueryPerformanceCounter & QueryPerformanceFrequency APIs. Other methods
    are unlikely to be precise enough.
     
    Dave
     
    • Proposed as answer by jinzai Tuesday, May 18, 2010 1:39 PM
    • Marked as answer by Amare1982 Wednesday, May 19, 2010 3:24 AM
    Tuesday, May 18, 2010 8:29 AM

All replies

  • Use GetTickCount
    Nikita Leontiev
    • Marked as answer by Amare1982 Wednesday, May 19, 2010 3:24 AM
    Tuesday, May 18, 2010 7:29 AM
  • > Is there any way of getting time taken by a function in Visual C++ 2008
    > ? I am using time_t but that's giving me the answer in seconds.
     
    For high precision timing, have a look at using the
    QueryPerformanceCounter & QueryPerformanceFrequency APIs. Other methods
    are unlikely to be precise enough.
     
    Dave
     
    • Proposed as answer by jinzai Tuesday, May 18, 2010 1:39 PM
    • Marked as answer by Amare1982 Wednesday, May 19, 2010 3:24 AM
    Tuesday, May 18, 2010 8:29 AM
  • So the basic answer is no, you have to use Operating System specific functions.
    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://c2kblog.blogspot.com/
    Tuesday, May 18, 2010 1:25 PM
  • Thanks Nikita, that's exactly what I was looking for.

    Amare

    Thursday, May 20, 2010 7:59 PM