是否有一些库可以帮助编写工具,如测量方法的执行时间
本文关键字:工具 测量 方法 执行时间 帮助 是否 | 更新日期: 2023-09-27 17:49:46
有什么库可以帮助完成这些任务吗?
可以使用Stopwatch类
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
}
}
MSDN
PostSharp - performance Counters
Visual Studio有一个分析器——我想它只在Pro版及以上版本中可用。总的来说,它工作得很好。
如果你有更具体或特殊的需求,你可能想看看PostSharp或其他附加组件