CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2011
    Posts
    25

    How to accurately time process execution

    Hi, is it possible to more accurately determine the performance of my code as opposed to GetTickCount or higher resolutions versions such as QueryPerformanceCounter?

    The problem with GetTickCount is that it only measures the absolute time my code takes to execute which can be can be distorted by background processing and is therefore not a completely accurate measure i.e. it serves as a guide only. Higher resolution timers don't fix this eg QueryPerformanceCounter. So how can I determine the CPU time that my process used to execute (independently to all other processes running in the background)?

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: How to accurately time process execution

    Take a look at GetProcessTimes.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Jan 2011
    Posts
    25

    Re: How to accurately time process execution

    Hi ovidiucucu

    I tried using it, however, it seems to return exactly the same numbers as gettickcount each and every call, i.e., it is unable to return the cpu time share used by my process.

    If there is no way to do this, perhaps it is because Windows is a more commercially focused OS and not designed for serious performance testing, issues and implementations?

  4. #4
    Join Date
    Oct 2008
    Posts
    1,456

    Re: How to accurately time process execution

    starting from Vista, there's also the QueryProcessCycleTime API; anyway, I think you should be able of retriving an equivalent estimate via the API suggested by ovidiucucu as well ...

    that said

    Quote Originally Posted by Witis View Post
    perhaps it is because Windows is a more commercially focused OS and not designed for serious performance testing, issues and implementations?
    this has nothing to do with being "commercial" or not ( whatever it means ), it's just that windows is not a real time os, hence it gives no strict guarantees on the timing of side-effects of your code, making such "true-cpu-time" measurements simply pointless. BTW, the exact number of cpu cycles used by a thread can depend on an amount of difficult to track factors, why are you interested in such a measurement ? Provided you develop for general purpose OSes, I don't think this would qualify as "serius performance testing" ...

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to accurately time process execution

    Quote Originally Posted by Witis View Post
    Hi ovidiucucu

    I tried using it, however, it seems to return exactly the same numbers as gettickcount each and every call, i.e., it is unable to return the cpu time share used by my process.
    “Calendar” time (like GetTickCount returns) will differ from thread time only if your process was unable to get all the CPU time it needed.
    Was your system overloaded?
    With modern equipment, your process might even get a full core for exclusive use...
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured