How to calculate program execution time?

  • Thread starter Thread starter CodeMonkey
  • Start date Start date
  • Tags Tags
    Program Time
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 25K views
CodeMonkey
Messages
11
Reaction score
0
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?
 
Physics news on Phys.org
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.
 
Sorry I shouldve added that I'm new to this. Can you please tell me which namespace, class and methods to use in Csharp?
 
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'