在Windows系统需要类似time
统计命令执行时间的方法
@REM time_cost.cmd
@echo off
@setlocal
echo ==========time cost start %time%==========
set "ts=%time%"
cmd /c %*
set "te=%time%"
echo ==========time cost end %te%==========
if "%te:~,2%" lss "%ts:~,2%" set "add=+24"
set /a "seconds=((%te:~,2%-%ts:~,2%%add%)*3600+(1%te:~3,2%%%100-1%ts:~3,2%%%100)*60+(1%te:~6,2%%%100-1%ts:~6,2%%%100))"
set /a "ms=(1%te:~-2%%%100-1%ts:~-2%%%100)"
if %ms% lss 0 (
set /a "ms=(1000%ms%)"
set /a "seconds=(%seconds%-1)"
)
set "ms0=100%ms%"
set "ms0=%ms0:~-3%"
echo time cost %seconds%.%ms0% s
执行命令之前
e:\>time_cost cd
==========time cost start 13:00:19.60==========
e:\
==========time cost end 13:00:19.69==========
time cost 0.009 s