【C#-程序时间计数器】如何计算某些步骤/过程耗时多少?

使用Stopwatch对象,TimeSpan对象

Stopwatch sw = new Stopwatch();//跑表,该类可以进行时间的统计 命名空间using System.Diagnostics;
sw.Start(); //跑表开始
//花费时间的目标 sw.Stop(); //跑表结束 TimeSpan ts = sw.Elapsed; //统计到的时间 Console.WriteLine(ts.Milliseconds); //输出统计到的时间的毫秒数
原文地址:https://www.cnblogs.com/Sukie-s-home/p/5803176.html