How to calculate the runtime of your C #, Windows application.
Are there well-known methods?
System Diagnostics Process . GetCurrentProcess() . TotalProcessorTime - CPU time used by the process (user mode and kernel mode). Use UserProcessorTime and PrivilegedProcessorTime for individual values.
System
Diagnostics
Process
GetCurrentProcess()
TotalProcessorTime
UserProcessorTime
PrivilegedProcessorTime
System Diagnostics Process . GetCurrentProcess() . StartTime - gives in combination with DateTime . Now the execution time of the process.
StartTime
DateTime
Now
Use System . Diagnostics StopWatch for profiling isolated tasks.
StopWatch
For advanced tasks you can use System . Diagnostics PerformanceCounter .
PerformanceCounter
You may also be interested in PostSharp ( http://www.postsharp.org/ ). You can start it when any method starts or stops.
Use the GetTickCount () API function when entering Main () and again when you are about to exit it, and get the difference between them to get the number of milliseconds your program has done.