elapsed time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
g2c
Posts: 2
Joined: 11 Mar 2015 13:33

elapsed time

#1 Post by g2c » 11 Mar 2015 14:55

hello,

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 http://stackoverflow.com/questions/9922 ... 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
http://www.computerhope.com/forum/index ... 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%

Squashman
Expert
Posts: 4198
Joined: 23 Dec 2011 13:59

Re: elapsed time

#2 Post by Squashman » 11 Mar 2015 18:58

viewtopic.php?p=38387

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
setlocal

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

Aacini
Expert
Posts: 1670
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: elapsed time

#3 Post by Aacini » 11 Mar 2015 20:13

http://stackoverflow.com/questions/9922 ... 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%


viewtopic.php?f=3&t=6271


Antonio

g2c
Posts: 2
Joined: 11 Mar 2015 13:33

Re: elapsed time

#4 Post by g2c » 26 Mar 2015 03:29

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

Post Reply