I have a batch file which executes a Qlikview file, I need to log the reload time taken in a text file, for which I need to store the time at which the script started in a variable, another variable storing the end time and finally dumping the difference between the times in a text file. Please suggest how to do this.
Asked
Active
Viewed 76 times
0
-
refer to this : http://stackoverflow.com/questions/739606/how-long-a-batch-file-takes-to-execute – r3ap3r Mar 27 '14 at 08:24
-
take a look at ptime: http://stackoverflow.com/a/9578588/1037208 . It's very easy to use. – OSH Mar 27 '14 at 08:31
1 Answers
0
elapsed.bat
@echo off
:: calculate elapsed time
:: if a supplied parameter starts '/' then put elapsed in /name
:: if any other parameter, re-start
set y$1=%1
if DEFINED y$1 IF "%y$1:~0,1%"=="/" (SET "y$3=%y$1:~1%") else (for %%i in (y$3 yeh yem yes yec) do set %%i=)
call :proc
if not defined yeh echo -- start elapsed --
if not defined yeh goto nocalc
set /a y$2=((((%yeh% * 60) + %yem%) * 60) + %yes%) * 100 + %yec%
set /a y$1=((((%y$h% * 60) + %y$m%) * 60) + %y$s%) * 100 + %y$c%
if %y$2% GTR %y$1% set /a y$1=%y$1% + 8640000
set /a y$2=%y$1% - %y$2%
SET /a y$1=y$2 / 100
SET /a y$2=y$2 %% 100
SET y$2=00%y$2%
SET y$2=%y$1%.%y$2:~-2% sec elapsed
IF DEFINED y$3 (SET %y$3%=%y$2%) ELSE (echo %y$2%)
:nocalc
set yeh=%y$h%
set yem=%y$m%
set yes=%y$s%
set yec=%y$c%
for %%i in (y$1 y$2 y$c y$m y$s y$h y$3) do set %%i=
goto :eof
:proc
set y$1=%time%
call :putdec y$c %y$1:~-2%
call :putdec y$s %y$1:~-5,2%
call :putdec y$m %y$1:~-8,2%
call :putdec y$h %y$1:~0,2%
goto :eof
:putdec
set y$2=%2
if %y$2:~-1%==: set y$2=0%y$2:~0,1%
set /a %1=1%y$2% - 100
goto :eof
I wrote this a long time ago - no doubt it could be improved.
call elapsed
will start a timer (stores the time in yeh
)
call elapsed
a second time will report the elapsed time.
call elapsed /var
will assign the elapsed time to var
call elapsed anythingelse
will re-start the timer.

Magoo
- 77,302
- 8
- 62
- 84