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

后端 未结 30 2976
南笙
南笙 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:04

    The answer of driblio can be made a little shorter (though not much readable)

    @echo off
    
    :: Calculate the start timestamp
    set _time=%time%
    set /a _hours=100%_time:~0,2%%%100,_min=100%_time:~3,2%%%100,_sec=100%_time:~6,2%%%100,_cs=%_time:~9,2%
    set /a _started=_hours*60*60*100+_min*60*100+_sec*100+_cs
    
    
    :: yourCommandHere
    
    
    :: Calculate the difference in cSeconds
    set _time=%time%
    set /a _hours=100%_time:~0,2%%%100,_min=100%_time:~3,2%%%100,_sec=100%_time:~6,2%%%100,_cs=%_time:~9,2%
    set /a _duration=_hours*60*60*100+_min*60*100+_sec*100+_cs-_started
    
    :: Populate variables for rendering (100+ needed for padding)
    set /a _hours=_duration/60/60/100,_min=100+_duration/60/100%%60,_sec=100+(_duration/100%%60%%60),_cs=100+_duration%%100
    
    echo Done at: %_time% took : %_hours%:%_min:~-2%:%_sec:~-2%.%_cs:~-2%
    
    ::prints something like:
    ::Done at: 12:37:53,70 took: 0:02:03.55
    

    To the remark of Luke Sampson this version is octal safe, though the task should be completed in 24 hours.

提交回复
热议问题