using system.diagnostics; stopwatch sw = new stopwatch(); sw.start(); //开始计时 //添加需要计算执行时间的代码 sw.stop(); //停止计时 console.writeline("执行完成耗时:{0}", sw.elapsedmilliseconds);
start():开始或继续计时
stop():停止计时
reset():清空计时
restart():清空计时并开始计时
黄山市民网:https://www.huangshanshimin.com/