Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate method execution time in c# while debugging in visual studio 2010?

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?

like image 342
Md. Mufazzal Hussain Avatar asked Oct 28 '15 08:10

Md. Mufazzal Hussain


People also ask

How do you calculate execution time?

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.

What is execution time of a program?

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.


1 Answers

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.

like image 170
Tomas Grosup Avatar answered Sep 30 '22 20:09

Tomas Grosup