
























计算代码段运行的时间长度,用Stopwatch类
1
Stopwatch sw = new Stopwatch();
2
sw.Start();
3
Thread.Sleep(3000);
4
sw.Stop();
5
Console.WriteLine(sw.ElapsedMilliseconds());
每次获取时间都要写这么几行,为此封装一个计算时间的类
Code
调用的时候:
1
using (RunningTimer timer = new RunningTimer("test"))
2
{
3
Thread.Sleep(3000);
4
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。