Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to calculate program execution time?

  1. Nov 13, 2007 #1
    I'm using VS and coding in Java, C++ and C#. What are the methods to use to display the time it takes for the program to execute in ms?
     
  2. jcsd
  3. Nov 13, 2007 #2

    rcgldr

    User Avatar
    Homework Helper

    I've used the following:

    QueryPerformanceCounter()
    Highest resolution timer, but includes overhead from other tasks. Still I found it to be the best. Using SetThreadPriority() to bump up priority should reduce overhead from other tasks.

    GetProcessTimes()
    Supposed to exclude overhead from other processes, but seems to include interrupt overhead. timeBeginPeriod() (requires a later timeEndPeriod()) can be used increase the tick rate, but this also seems to increase the reported time, indicating that interrupt overhead is included in the process times.

    clock()
    A more generic time call. On Windows XP, reports time in milliseconds, but appears to be based on a 64hz ticker.
     
  4. Nov 13, 2007 #3

    ranger

    User Avatar
    Gold Member

    It is quite easy to do it on a UNIX based system. You can make use of the time command. I've found a very interesting paper that talks about program execution time:
    http://csapp.cs.cmu.edu/public/ch9-preview.pdf
     
  5. Nov 13, 2007 #4
    Sorry I shouldve added that I'm new to this. Can you please tell me which namespace, class and methods to use in Csharp?
     
  6. Nov 14, 2007 #5

    jim mcnamara

    User Avatar
    Science Advisor
    Gold Member

    If this is a critical app, consider profiling. There are profilers for all of .NET.

    Profilers time each function in your code so you can see where you have problems. There are java profilers as well. Some are free or have trial periods.

    google for '.net profiler'
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?