miscellaneous-scripts/stopwatch.cmd

60 lines
1.3 KiB
Batchfile

@echo off
setlocal
set Count=100
call :StartTimer
set Iteration=0
:FindTest
tasklist /fi "imagename eq BogusProcess.exe" |find ":" > nul
set /a Iteration=%Iteration%+1
if "%Iteration%"=="%Count%" goto FindTestBreak
goto FindTest
:FindTestBreak
call :StopTimer
call :DisplayTimerResult
pause
call :StartTimer
set Iteration=0
:FindstrTest
tasklist /fi "imagename eq BogusProcess.exe" |findstr /r /c:"^INFO:" > nul
set /a Iteration=%Iteration%+1
if "%Iteration%"=="%Count%" goto FindstrTestBreak
goto FindstrTest
:FindstrTestBreak
call :StopTimer
call :DisplayTimerResult
goto :EOF
:StartTimer
:: Store start time
set StartTIME=%TIME%
for /f "usebackq tokens=1-4 delims=:., " %%f in (`echo %StartTIME: =0%`) do set /a Start100S=1%%f*360000+1%%g*6000+1%%h*100+1%%i-36610100
goto :EOF
:StopTimer
:: Get the end time
set StopTIME=%TIME%
for /f "usebackq tokens=1-4 delims=:., " %%f in (`echo %StopTIME: =0%`) do set /a Stop100S=1%%f*360000+1%%g*6000+1%%h*100+1%%i-36610100
:: Test midnight rollover. If so, add 1 day=8640000 1/100ths secs
if %Stop100S% LSS %Start100S% set /a Stop100S+=8640000
set /a TookTime=%Stop100S%-%Start100S%
set TookTimePadded=0%TookTime%
goto :EOF
:DisplayTimerResult
:: Show timer start/stop/delta
echo Started: %StartTime%
echo Stopped: %StopTime%
echo Elapsed: %TookTime:~0,-2%.%TookTimePadded:~-2% seconds
goto :EOF
endlocal