常用计算程序运行耗时

方式1

DateTime beginTime = DateTime.Now;
//code...
DateTime endTime = DateTime.Now;
Console.WriteLine($"耗时:{(endTime-beginTime).TotalMilliseconds}ms");

方式2

Stopwatch sw = new Stopwatch();
sw.Start();
//code...
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine($"耗时:{ts.TotalMilliseconds}ms");
最后修改:2024 年 05 月 02 日
如果觉得我的文章对你有用,请随意赞赏