@echo off
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo DETERMINE HOW LONG IT TOOK A PROGRAM TO RUN
echo The demo will run for 1 - 60 seconds.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PAUSE
cls
:: Get the time (in Julian seconds) that the program began running
set PgmName=DemoFake_Pgm
FDATE /Ff /Osecond# /VBegS
FDATE /Ff /Ohh:mm:ss /P"%PgmName% execution begins at "
:: ~~~~~~~~~ DEMO BEGIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: For purposes of this demo, we simulate execution of a
:: program by looping until the minute changes. In your real
:: batch file, you would put your program statements here.
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FDATE /Ff /Ohhmm /vBegM
:BegLoop
rem Since this is a demo, give the folks something to watch
FDATE /Ff /Osecond# /vSeconds
FDATE /F#dif /A%Seconds% /B%BegS% /P".... elapsed time: " /S" seconds."
FDATE /Ff /Ohhmm /vNowM
if (%NowM%)==(%BegM%) goto BegLoop
set BegM=
set NowM=
:: ~~~~~~~~~ DEMO END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: Get the time (in Julian seconds) that the program finished
FDATE /Ff /Osecond# /vEndS
:: tell the user the time that the program finished
FDATE /Ff /Ohh:mm:ss /P"%PgmName% execution ends at "
:: calculate run time (difference between start time and end time)
FDATE /F#dif /A%EndS% /B%BegS% /vSeconds
:: convert seconds to minutes + seconds format
FDATE /F#idiv /A%Seconds% /B60 /vMinutes
FDATE /F#mod /A%Seconds% /B60 /vMinSecs
:: tell the user how long the program took to run
echo Runtime: %Seconds% seconds (%Minutes% minutes %MinSecs% seconds)
:: cleanup
set PgmName=
set BegS=
set EndS=
set Seconds=
set Minutes=
set MinSecs=