This script by bluesxman on the forum can be used to accurately measure the time elapsed by some other process or script. To use it start the timer with CALL timer.cmd start, then run the other process and then CALL timer.cmd stop when finished.

@echo off

set time=%~2
set time=%time: =0%

set stamp.file=%temp%\%~n0.stamp

if /i "%~1" EQU "start" call :make.stamp
if /i "%~1" EQU "stop"  call :read.stamp stop
if /i "%~1" EQU "lap"   call :read.stamp lap
if    "%~1" EQU ""      call :status

goto :EOF


 if exist "%stamp.file%" (
	 if /i "%~1" NEQ "/q" echo:Timer is active.
	 exit /b 0

 echo:Timer is not active.
 exit /b 1


 if exist "%stamp.file%" call :read.stamp stop
 set start.time=%time%

 (echo:%start.time%) > "%stamp.file%"
 echo:Timer started %start.time%
 goto :EOF


 call :status /q
 if errorlevel 1 goto :EOF
 set stop.time=%time%
 set /p start.time=< "%stamp.file%"

 echo:Timer started %start.time%
 echo:Timer %1ped %stop.time%

 if %1 EQU stop del "%stamp.file%"

 call :calc.time.code %start.time%
 set start.time.code=%errorlevel%

 call :calc.time.code %stop.time%
 set stop.time.code=%errorlevel%

 set /a diff.time.code=stop.time.code - start.time.code

 if %diff.time.code% LSS 0 set /a diff.time.code+=(24 * 60 * 60 * 100)


 set /a hs=diff.time.code %% 100
 set /a diff.time.code/=100
 set /a ss=diff.time.code %% 60
 set /a diff.time.code/=60
 set /a mm=diff.time.code %% 60
 set /a diff.time.code/=60
 set /a hh=diff.time.code

 set hh=0%hh%
 set mm=0%mm%
 set ss=0%ss%
 set hs=0%hs%

 endlocal & set diff.time=%hh:~-2%:%mm:~-2%:%ss:~-2%.%hs:~-2%

 echo %diff.time.code% hundredths of a second
 echo %diff.time%

 goto :EOF


 for /f "usebackq tokens=1,2,3,4 delims=:." %%a in ('%1') do (
    set hh=%%a
    set mm=%%b
    set ss=%%c
    set hs=%%d

 set /a hh=((%hh:~0,1% * 10) + %hh:~1,1%) * 60 * 60 * 100
 set /a mm=((%mm:~0,1% * 10) + %mm:~1,1%) * 60 * 100
 set /a ss=((%ss:~0,1% * 10) + %ss:~1,1%) * 100
 set /a hs=((%hs:~0,1% * 10) + %hs:~1,1%)

 set /a time.code=hh + mm + ss + hs
 endlocal & exit /b %time.code%

When measuring short time periods run the timer several times and take an average, this will smooth out the effect of any background processes and hard drive variations.

“You go away for a long time and return a different person ~ you never come all the way back” ~ Paul Theroux


StrLen - Calculate the length of a string.
tdiff.cmd - Time difference in Hours/Minutes.
Chronometer/Timer app - SS64 Forum

Copyright © SS64.com 1999-2019
Some rights reserved