简体   繁体   English

在Visual Studio 2010中调试时如何在C#中计算方法执行时间?

[英]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.

相关问题 在调试Visual Studio 2010 MVC C#程序时如何从键盘获得输入? - How do I get input from the keyboard while debugging a Visual Studio 2010 MVC C# program? 在C#中调试时,Visual Studio如何评估属性? - How does Visual Studio evaluate properties while debugging in C#? 在 C# 中的 Visual Studio(2008 和 2010)上调试时“忽略并继续”可能吗? - “Ignore and continue” while debugging on Visual Studio (2008 & 2010) in C# possible? C#,visual studio 2010,如何停止一个方法,线程? - C#, visual studio 2010, how to stop a method, threads? 如何在c#中计算异步方法的执行时间 - how to calculate execution time of a async method in c# Visual Studio 2010 C#调试MS数据集 - Visual studio 2010 C# debugging MS Dataset C#Visual Studio 2010无法开始调试 - C# Visual Studio 2010 doesn't start debugging 在Visual Studio C#Express 2010中调试Nunit测试 - Debugging Nunit tests in Visual Studio C# Express 2010 在Visual Studio Express中计算方法执行时间(没有可用的分析器)? - calculate method execution time in Visual Studio Express (No profiler available)? 使用Visual Studio 2010 C#进行调试时,如何避免进入常用功能? - When debugging using Visual Studio 2010 C#, how to avoid stepping into common functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM