C#中计时器的操作
2021-05-05 15:28
标签:ati read start logs stat ons code string long 我们可以用Stopwatch类获得程序的运行时间,在优化代码时,可以用此方法来查看优化前后程序所耗费的时间 参考:用Stopwatch类获得程序运行时间 C#中计时器的操作 标签:ati read start logs stat ons code string long 原文地址:http://www.cnblogs.com/wuqiuxue/p/7680180.htmlstatic void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
long num = 0;
sw.Reset();
sw = Stopwatch.StartNew();
for (int i = 1; i 100000000; i++) num += 1;
sw.Stop();
TimeSpan el = sw.Elapsed;
Console.WriteLine("花费 {0} ", el);
long ms = sw.ElapsedMilliseconds;
Console.WriteLine("花费 {0} 毫秒", ms);
long tk = sw.ElapsedTicks;
Console.WriteLine("花费 {0} ticks", tk);
Console.ReadKey();
}