1.时间测试

DateTime starttime = DateTime.Now;

TimeSpan timespan;

程序主体

timespan = DateTime.Now.Subtract(starttime);//获取就是开始时间很结束时间差

2.用于.NET环境的时间测试(只测试代码在自身进程中的时间)

.NET环境为执行无用单元收集调用提供了专门的对象--GC。为了是系统执行无用单元收集。

GC.Collect();

程序等待堆上对象的所有finalizer方法都运行后再继续。

GC.WaitForPendingFinalizers();

TimeSpan starttime;

starttime = Process.GetCurrentProcess().Threads[0].UserProcessorTime;

程序主体

TimeSpan endtime = Process.GetCurrentProcess().Threads[0].UserProcessorTime.Subtract(starttime);//获取就是开始时间很结束时间差

相关文章:

  • 2021-08-25
  • 2021-12-14
  • 2021-09-07
  • 2021-12-15
  • 2021-09-16
  • 2021-06-21
  • 2022-12-23
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2021-07-04
  • 2021-07-03
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案