如何使用Windows批处理文件来衡量控制台应用程序的性能?

5 windows batch-file

如何编写简单的批处理文件来衡量基于控制台的应用程序的性能?控制台应用程序接受两个命令行参数.

我想得到:

StartTime = System Dos time
myconsoleapp arg1, arg2
StopTime = System Dos Time
timeDelta = stoptime - starttime
Run Code Online (Sandbox Code Playgroud)

我会将timeDelta写入控制台上的文件或显示.

jeb*_*jeb 7

纯批量解决方案可以.

@echo off
set "startTime=%time%"
for /L %%n in (1,1, 1000) do <nul set /p "="
set "stopTime=%time%"
call :timeDiff diff startTime stopTime
echo %diff% milli seconds
goto :eof

:timeDiff
setlocal
call :timeToMS time1 "%~2"
call :timeToMS time2 "%~3"
set /a diff=time2-time1
(
  ENDLOCAL
  set "%~1=%diff%"
  goto :eof
)

:timeToMS
::### WARNING, enclose the time in " ", because it can contain comma seperators
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=1,2,3,4 delims=:,.^ " %%a IN ("!%~2!") DO (
  set /a "ms=(((30%%a%%100)*60+7%%b)*60+3%%c-42300)*1000+(1%%d0 %% 1000)"
)
(
  ENDLOCAL
  set %~1=%ms%
  goto :eof
)
Run Code Online (Sandbox Code Playgroud)