//监控性能需引用 System.Diagnostics
//荣达2022.11.24测试代码,检测打印耗时
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start(); // 开始监视代码运行时间
//.........代码..................//
stopwatch.Stop(); // 停止监视
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
string seconds = timespan.TotalSeconds.ToString("#0.00000000 "); // 总秒数
string minutes = timespan.TotalMinutes.ToString("#0.00000000 "); // 总分钟
string milliseconds = timespan.TotalMilliseconds.ToString("#0.00000000 ");
//总毫秒数
string hours = timespan.TotalHours.ToString("#0.00000000 "); // 总小时
//将消耗时间显示到VS的”输出“窗口
Console.WriteLine(string.Format("消耗时间(秒):{0}", seconds));
需要检测代码块运行耗时多久时,可以使用此方法在控制台看到结果。非常好用!
相关推荐: C#反射将静态类数据反射到字典并读取不同分支的字典数据
然后根据switch case匹配的字典加载/// <summary> /// 获取警报的端口状态 /// </summary> private Dictionary<uint, Dictionary<string, uin…
© 版权声明
THE END
暂无评论内容