How to calculate program execution time?

  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. rcgldr

    rcgldr 7,409
    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. ranger

    ranger 1,684
    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. 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. jim mcnamara

    jim mcnamara 1,482
    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 a link to this question via email, Google+, Twitter, or Facebook

Have something to add?