首页 > Windows开发 > 详细

C# 中如何精确地测量一段逻辑的执行时间

时间:2020-05-09 19:10:15      阅读:39      评论:0      收藏:0      [点我收藏+]

C#中提供了一个类Stopwatch,可以实现这个需求,当然了,不通过这个类也可以实现类似的功能。下面简单介绍一下使用方法,直接上代码:

1 Stopwatch stopwatch = new Stopwatch();
2 stopwatch.Start();
3 //TODO        
4 stopwatch.Stop();
5 int totalSeconds = (int)(stopwatch.ElapsedMilliseconds / 1000f);
6 int minutes = (int)(totalSeconds / 60f);
7 int seconds = totalSeconds % 60;
8 string str = string.Format("耗时: {0} 分 {1} 秒。", minutes, seconds);

 

C# 中如何精确地测量一段逻辑的执行时间

原文:https://www.cnblogs.com/luguoshuai/p/12859529.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!