How do I measure execution time of a command on th

2018-12-31 10:44发布

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

29条回答
浪荡孟婆
2楼-- · 2018-12-31 10:46

Process Explorer will show kernel time, user time, and wall time (and lots of other stuff) as long as you click on the process before it exits. It is not a command-line tool, but it is immensely useful anyway.

查看更多
初与友歌
3楼-- · 2018-12-31 10:48

Hehe, the most simple solution might be this:

echo %time%
YourApp.exe
echo %time%

This works on every Windows out of the box.


In case of an application using console output, it might be convenient to store the starting time in a temporary variable:

set startTime=%time%
YourApp.exe
echo Start Time: %startTime%
echo Finish Time: %time%
查看更多
怪性笑人.
4楼-- · 2018-12-31 10:50

If you have a command window open and call the commands manually, you can display a timestamp on each prompt, e.g.

prompt $d $t $_$P$G

It gives you something like:

23.03.2009 15:45:50,77

C:\>

If you have a small batch script that executes your commands, have an empty line before each command, e.g.

(empty line)

myCommand.exe

(next empty line)

myCommand2.exe

You can calculate the execution time for each command by the time information in the prompt. The best would probably be to pipe the output to a textfile for further analysis:

MyBatchFile.bat > output.txt
查看更多
孤独寂梦人
5楼-- · 2018-12-31 10:51

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.
查看更多
人间绝色
6楼-- · 2018-12-31 10:52

Using a sub to return time in hundredths of second

::tiemeit.cmd
@echo off
Setlocal EnableDelayedExpansion

call :clock 

::call your_command  or more > null to pipe this batch after your_command

call :clock

echo %timed%
pause
goto:eof

:clock
if not defined timed set timed=0
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( 
set /A timed = "(((1%%a - 100) * 60 + (1%%b - 100)) * 60 + (1%%c - 100))  * 100 + (1%%d - 100)- %timed%"
)
goto:eof
查看更多
忆尘夕之涩
7楼-- · 2018-12-31 10:53

Since others are recommending installing things like freeware and PowerShell, you could also install Cygwin, which would give you access to many basic Unix commands like time:

abe@abe-PC:~$ time sleep 5

real    0m5.012s
user    0m0.000s
sys 0m0.000s

Not sure how much overhead Cygwin adds.

查看更多
登录 后发表回答