I’ve a C# method written in Visual studio 2010 where several loop is executing. Now I want to calculate the method execution time while debugging.
I know that it is possible to calculate time using Stopwatch in my code but I am not authorized to change the code. So is there any way to calculate the method execution time while debugging?
The difference between the end time and start time is the execution time. Get the execution time by subtracting the start time from the end time.
Execution time : The execution time or CPU time of a given task is defined as the time spent by the system executing that task in other way you can say the time during which a program is running.
Add breakpoints before and after the method execution. Right click the breakpoints and choose "When hit" In the dialog window, you can put in a print statement such as
"{DateTime.Now.Ticks}"
After both breakpoints are hit, you have timings before and after the method execution.
Please note that this will only have the precision of DateTime and will be affected by the debugging overhead. In case you want to do some real benchmarking, use specialized profilers instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With