[英]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. 我有一个用Visual Studio 2010编写的C#方法,其中正在执行多个循环。 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?
那么,有什么方法可以在调试时计算方法的执行时间吗?
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. 请注意,这只会具有DateTime的精度,并且会受到调试开销的影响。 In case you want to do some real benchmarking, use specialized profilers instead.
如果您想进行一些实际的基准测试,请改用专门的分析器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.