How to calculate program execution time?

  • Thread starter CodeMonkey
  • Start date
  • #1
11
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?
 

Answers and Replies

  • #2
rcgldr
Homework Helper
8,706
534
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
11
0
Sorry I shouldve added that I'm new to this. Can you please tell me which namespace, class and methods to use in Csharp?
 
  • #5
jim mcnamara
Mentor
4,012
2,452
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'
 

Related Threads on How to calculate program execution time?

  • Last Post
Replies
14
Views
602
  • Last Post
Replies
10
Views
2K
Replies
4
Views
25K
Replies
3
Views
11K
Replies
11
Views
2K
Replies
1
Views
2K
Replies
5
Views
1K
Replies
18
Views
2K
Top