Md. Mufazzal Hussain
Md. Mufazzal Hussain

Reputation: 244

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?

Upvotes: 6

Views: 2340

Answers (1)

Tomas Grosup
Tomas Grosup

Reputation: 6514

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.

Upvotes: 4

Related Questions