How to calculate program execution time?

  • Thread starter Thread starter CodeMonkey
  • Start date Start date
  • Tags Tags
    Program Time
Click For Summary

Discussion Overview

The discussion centers around methods for calculating program execution time in various programming languages, specifically Java, C++, and C#. Participants explore different timing functions and tools available in different operating systems, as well as considerations for accuracy and overhead.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant mentions using QueryPerformanceCounter() for high-resolution timing but notes it includes overhead from other tasks.
  • Another participant discusses GetProcessTimes(), suggesting it should exclude overhead from other processes but indicates it may still include interrupt overhead.
  • A different participant points out that on UNIX-based systems, the time command can be used to measure execution time and references a related paper.
  • One participant requests clarification on the specific namespace, class, and methods to use in C# for timing execution.
  • Another participant suggests considering profiling for critical applications, mentioning that profilers can provide detailed timing for each function in the code.

Areas of Agreement / Disagreement

Participants express various methods and tools for measuring execution time, but there is no consensus on the best approach or method, as different tools may have different overheads and applicability depending on the context.

Contextual Notes

Some methods discussed may have limitations related to overhead from other processes or interrupts, and the accuracy of timing may depend on the specific environment and implementation.

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?
 
Technology 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'
 

Similar threads

Replies
86
Views
3K
Replies
6
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
6
Views
2K
Replies
38
Views
5K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 64 ·
3
Replies
64
Views
8K
Replies
7
Views
4K
  • · Replies 22 ·
Replies
22
Views
2K
Replies
3
Views
3K