How do I measure execution time of a command on the Windows command line?

后端 未结 30 2947
南笙
南笙 2020-11-22 09:44

Is there a built-in way to measure execution time of a command on the Windows command line?

30条回答
  •  渐次进展
    2020-11-22 10:06

    As long as it doesn't last longer than 24hours...

    @echo off
    
    set starttime=%TIME%
    set startcsec=%STARTTIME:~9,2%
    set startsecs=%STARTTIME:~6,2%
    set startmins=%STARTTIME:~3,2%
    set starthour=%STARTTIME:~0,2%
    set /a starttime=(%starthour%*60*60*100)+(%startmins%*60*100)+(%startsecs%*100)+(%startcsec%)
    
    :TimeThis
    ping localhost 
    
    set endtime=%time%
    set endcsec=%endTIME:~9,2%
    set endsecs=%endTIME:~6,2%
    set endmins=%endTIME:~3,2%
    set endhour=%endTIME:~0,2%
    if %endhour% LSS %starthour% set /a endhour+=24
    set /a endtime=(%endhour%*60*60*100)+(%endmins%*60*100)+(%endsecs%*100)+(%endcsec%)
    
    set /a timetaken= ( %endtime% - %starttime% )
    set /a timetakens= %timetaken% / 100
    set timetaken=%timetakens%.%timetaken:~-2%
    
    echo.
    echo Took: %timetaken% sec.
    

提交回复
热议问题