c# - 在 C# 中使用时间戳来测试方法长度

标签 c# .net timestamp

我想测试一个方法运行需要多长时间,我想知道时间跨度是否是最好的方法?我不想记录方法的开始和结束,因为我听说由于创建和更新现有日志文件需要时间,因此记录不会提供准确的时间读数。如果时间跨度不是最好的方法,那么有什么建议是最好的吗?

最佳答案

最好使用专为此类事情设计的 Stopwatch 类。

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
DoSomething();
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;

关于c# - 在 C# 中使用时间戳来测试方法长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12845518/

相关文章:

c# - 为什么我无法修复错误 : A potentially dangerous Request. 从客户端检测到表单值(结果 ="<t:RequestSecurityTo...")

asp.net - 系统.IO.FileLoadException : Loading this assembly would produce a different grant set from other instances

c# - 新的 Mercosul 牌照正则表达式

Python:将复杂的日期和时间字符串转换为时间戳

timestamp - H.264 RTSP 绝对时间戳

C# DataGridView 添加行 - 验证时,我如何知道该行是新行且尚未提交?

c# - Asp.net MVC 2 Request.files [""] 总是返回 null

c# - 如何在 ASP.NET MVC 4 Razor 项目的 View 中显示集合?

c# - 使用数据访问层为 3 层安排 dotnet 核心应用程序

java - ResultSet 元数据返回时间戳而不是日期 Oracle JDBC