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

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

    This is a one-liner which avoids delayed expansion, which could disturb certain commands:

    cmd /E /C "prompt $T$$ & echo.%TIME%$ & COMMAND_TO_MEASURE & for %Z in (.) do rem/ "
    

    The output is something like:

    14:30:27.58$
    ...
    14:32:43.17$ rem/ 
    

    For long-term tests replace $T by $D, $T and %TIME% by %DATE%, %TIME% to include the date.

    To use this inside of a batch file, replace %Z by %%Z.


    Update

    Here is an improved one-liner (without delayed expansion too):

    cmd /E /C "prompt $D, $T$$ & (for %# in (.) do rem/ ) & COMMAND_TO_MEASURE & for %# in (.) do prompt"
    

    The output looks similar to this:

    2015/09/01, 14:30:27.58$ rem/ 
    ...
    2015/09/01, 14:32:43.17$ prompt
    

    This approach does not include the process of instancing a new cmd in the result, nor does it include the prompt command(s).

提交回复
热议问题