How to calculate program execution time?

  • Thread starter Thread starter CodeMonkey
  • Start date Start date
  • Tags Tags
    Program Time
AI Thread Summary
To measure program execution time in milliseconds while coding in Java, C++, and C# using Visual Studio, several methods are discussed. QueryPerformanceCounter() is highlighted as the highest resolution timer, though it may include overhead from other tasks. To mitigate this, adjusting thread priority with SetThreadPriority() can help. GetProcessTimes() is noted for excluding overhead from other processes, but it still captures interrupt overhead, which can skew results. The clock() function offers a more generic timing method, reporting time in milliseconds on Windows XP but is based on a 64hz ticker. For UNIX systems, the time command is recommended. For C#, users are advised to explore the appropriate namespace, class, and methods, and consider using profilers to analyze function execution times for performance issues. Various profilers are available for .NET and Java, some of which are free or offer trial versions.
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.
 
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
 
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'
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top