【C#】利用StopWatch监控代码执行时间

StopWatch:提供一组方法和属性,可用于准确地测量运行时间。

  1. 主要用到Start、Restart、Stop方法
  2. ElapsedMilliseconds属性获取执行时间,单位:毫秒
  3. 缺点:不支持多线程,适用于单线程
Stopwatch execTime = new Stopwatch();
execTime.Start();
//需要监测的代码的执行的时间
execTime.Stop();
Console.WriteLine($"**********执行时间:{execTime.ElapsedMilliseconds.ToString()}");
posted @ 2020-11-03 15:26  玫瑰下的阿司匹林  Views(200)  Comments(0)    收藏  举报