C# 测试一段代码的运行时间

Stopwatch stopWatch = new Stopwatch();
/开始
stopWatch.Start();

Type type = a.GetExportedTypes().First(t => t.Name == item.menuType);//要测试的代码

stopWatch.Stop();

TimeSpan ts = stopWatch.Elapsed;

double seconds = ts.TotalSeconds;//转换成秒

Console.WriteLine(seconds);

 

你可能感兴趣的:(C#)