C#程序运行计时

var stp = new System.Diagnostics.Stopwatch();
stp.Start();//计时启动


..........程序代码...........


stp.Stop();//停止计时
Classlog.WriterLog(string.Format("耗时:{0}毫秒",stp.ElapsedMilliseconds), "caltm");
stp.Restart();// 停止时间间隔测量,将运行时间重置为零,然后开始测量运行时间。


..........程序代码.................


Classlog.WriterLog(string.Format("耗时:{0}毫秒",stp.ElapsedMilliseconds), "caltm");
stp.Stop();

原文地址:https://www.cnblogs.com/LeiYang5237/p/8549847.html