我想测试一个方法运行需要多长时间,我想知道时间跨度是否是最好的方法?我不想记录方法的开始和结束,因为我听说由于创建和更新现有日志文件需要时间,因此记录不会提供准确的时间读数。如果时间跨度不是最好的方法,那么有什么建议是最好的吗?
最佳答案
最好使用专为此类事情设计的 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/