1.

Solve : Time taken by program?

Answer»

From a batch FILE, I am invoking a program and i want to calculate time taken by that program. Please let me know how can i achieve this
Thanks in Advance
This is a batch file I wrote a while BACK for exactly that purpose. I call it timer.bat.
Syntax:
timer [command [params]]
Code: [Select]@echo off
setlocal
set Start=%time%
%*
SET End=%time%

if %Start:~3,1% GEQ 1 (set /a StartMin=%Start:~3,2%) ELSE (set /a StartMin=%Start:~4,1%)
if %Start:~6,1% GEQ 1 (set /a StartSec=%Start:~6,2%) else (set /a StartSec=%Start:~7,1%)
if %Start:~9,1% GEQ 1 (set /a StartFrac=%Start:~9,2%) else (set /a StartFrac=%Start:~10,1%)
if %End:~3,1% GEQ 1 (set /a EndMin=%End:~3,2%) else (set /a EndMin=%End:~4,1%)
if %End:~6,1% GEQ 1 (set /a EndSec=%End:~6,2%) else (set /a EndSec=%End:~7,1%)
if %End:~9,1% GEQ 1 (set /a EndFrac=%End:~9,2%) else (set /a EndFrac=%End:~10,1%)

set /a StartSecs=(%Start:~0,2%*60*60)+(%StartMin%*60)+(%StartSec%)
set /a EndSecs=(%End:~0,2%*60*60)+(%EndMin%*60)+(%EndSec%)
if %EndSecs% LSS %StartSecs% set /a EndSecs+=24*60*60
set /a DurationSecs=%EndSecs%-%StartSecs%&set /a FracDelta=%EndFrac%-%StartFrac%

if %FracDelta% LSS 0 set /a DurationSecs-=1&set /a FracDelta+=100
if %DurationSecs% GEQ 60 (set /a FinalMins=%DurationSecs%/60&set /a FinalSecs=%DurationSecs%%%60) else (set FinalMins=0&set /a FinalSecs=%DurationSecs%)
if %FinalMins% LEQ 9 set FinalMins=0%FinalMins%
if %FinalSecs% LEQ 9 set FinalSecs=0%FinalSecs%
if %FracDelta% LEQ 9 set FracDelta=0%FracDelta%

echo The following command started at %Start% and completed at %End%
echo %*
echo.
echo Total duration was %FinalMins%:%FinalSecs%.%FracDelta% minutes.
The program you have sent is very useful. Is it possible to count the number of Hours taken also???( the program i will be invoking may take more than 1 Hour).If it is more than an hour it will still generate the proper number of minutes. For example, if it runs an hour and a half, the batch file will return 90 minutes.

If you want to include a calculation for hours, you can check to see if minutes is greater than 60. If yes hours = minutes / 60, and minutes = minutes % 60. If you UNDERSTAND the code well enough, you can try that yourself, or if you want me to provide the code for you, just let me know.Thanks for the inputs.
I will try myself to include code for counting Hours.



Discussion

No Comment Found