Page 1 of 1

elapsed time

Posted: 11 Mar 2015 14:55
by g2c

i am trying desperately to measure the duration of a task called within a dos batch loop running on a windows 8.1 64 bits and an seriously asking myself if this is at all possible

Thanks in advance for your help

Tried the procedure in ... batch-file
the expression
set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)

result in "Unbalanced parenthesis." whenever hour < 10

Tried the procedure in ... ic=78053.0

the expression in bold gives
"Invalid number. Numeric constants are either decimal (17), hexadecimal (0x11), or octal (021)."
whenever 8<seconds <10

echo start time=%TIME%
set HH=%TIME:~0,2%
echo Hour=%HH%
set MM=%TIME:~3,2%
echo minutes=%MM%
set /a MM=%MM% * 60
echo Total Seconds in given minutes=%MM%
set /a HH=%HH% * 3600
echo Total seconds in given Hours = %HH%
set SS=%TIME:~6,2%
echo seconds= %SS%
Set /a start=%HH% + %MM% + %SS%
echo start time in seconds =%start%

Re: elapsed time

Posted: 11 Mar 2015 18:58
by Squashman

dbenham wrote:getTimestap.bat can also be used to conveniently compute elapsed time of nearly any time interval, without worrying about the limits of batch arithmetic. This is extremely convenient for timing events.

Two calls to getTimestamp are used to store the current timestamp at the beginning and end of a process. The timestamps are expressed as milliseconds since midnight, January 1, 1970. Then one more call to getTimestamp is used to compute the interval. The date for the interval is specified as timestamp2 - timestamp1, and the format can provide the elapsed time in whatever units are required.

Code: Select all

@echo off

call getTimestamp -f {ums} -r t1
:: Some long running process here
call getTimestamp -f {ums} -r t2

:: This computes the elapsed time as decimal hours.
:: It supports both positive and negative intervals.
call getTimestamp -d %t2%-%t1% -f "{uhd} hours"

:: This computes the elapsed time as days, hours, mins, secs, ms
:: It only supports positive intervals
call getTimestamp -d %t2%-%t1% -f "{ud} days {hh}:{nn}:{ss}.{fff}" -u

Re: elapsed time

Posted: 11 Mar 2015 20:13
by Aacini ... 40#9935540

Code: Select all

@echo off

rem Get start time:
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
   set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"

rem Any process here...

rem Get end time:
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
   set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"

rem Get elapsed time:
set /A elapsed=end-start

rem Show elapsed time:
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
if %mm% lss 10 set mm=0%mm%
if %ss% lss 10 set ss=0%ss%
if %cc% lss 10 set cc=0%cc%
echo %hh%:%mm%:%ss%,%cc%



Re: elapsed time

Posted: 26 Mar 2015 03:29
by g2c
Thanks Antonio! I used it intensely and it helped me a lot. It does misbehave when interval crosses days but it's only one measurement error with no other consequences.

Thanks again.

... And thanks Squashman for attracting my attention to Antonio's code