stoptime %starttime%
...
...do something
...
stoptime %stoptime%
diff = calcdiff(stoptime, startime)
echo diff: diff
or
dotime -start
...
...do something
...
echo dotime -showelapsed
MS-DOS extensions for WinNT/Win2000 and external programs can be used
Regards
Peter
call :GetTime Start
:: Do Something
call :GetTime Finish
:: Return Time difference in seconds
set /a Diff=Finish-Start
if %Diff% LSS 0 set /a Diff=Diff+86400
set Start=
set Finish=
echo.%Diff%
pause
goto :eof
:GetTime
for /f "tokens=5-7 delims=:. " %%a in ('echo.^|time^|find "current"') do (
set HH=%%a
set MM=%%b
set SS=%%c)
if %HH:~0,1%==0 set HH=%HH:~1,1%
if %MM:~0,1%==0 set MM=%MM:~1,1%
if %SS:~0,1%==0 set SS=%SS:~1,1%
set /a %1=(HH*3600)+(MM*60)+SS
set HH=
set MM=
set SS=
goto :eof
4dos 7.00 (yes, new) has a timer function.
Something like TIMER / PROGRAM / ENDTIMER -> Show used time
"Peter Blatt" <pet...@redseven.com> wrote in message
news:3b503cef$0$19083$9b62...@news.freenet.de...
NOWMINUS is available via sig line 3.
NOWMINUS F16 Eitwas ; store time_t in "itwas"
NOWMINUS F16 S%itwas% Ediff ; store difference, secs, in "diff"
NOWMINUS F16 S%itwas% F2 Ediff ; " " hh:mm:ss, in "diff"
Known to work in DOS & Win98.
--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
The most obvious way:
Time 00:00:00,00
:: Do something
:
:
:: Show elapsed time
Echo. | Time | Find ","
Note: changing the system date could have unwanted side-effects since this action concerns all running apps and services.
If I remember correctly, there exist a number of stopwatch utilities (search simtel.net, for example).
Or, how about "playing" with VBScript/WSH?
Dim oSh, StartTime, EndTime
Set oSh = CreateObject("WScript.Shell")
StartTime = Timer
' Do something
oSh.Run "%COMSPEC% /C Mybatch.cmd",,True
EndTime = Timer
' Show elapsed time
WScript.Echo "Elapsed time in seconds:", EndTime - StartTime
HTH
--
Frank-Peter Schultze <fpsch...@my-deja.com>, http://www.fpschultze.de
please, again, for the x-th day this week: use
news: alt.msdos.batch.NT
for NT/W2000 specific questions.
Very likely, batch techniques for other OS used here, will not work in
NT/W2000, hence....
secondary: pure arithmetic is normally not possible within batch (or at
least not without rather advanced techniques, or some secondary
programming language, like qbasic or alike)
See faq for getting time, then subtracting within i.e. qbasic should be
easy.
--
Lieve - Ri(n)ksken(s)
TUF Greetings from Rumbeke, Belgium
VBscript has a DATEDIFF function for this purpose.
http://msdn.microsoft.com/scripting/default.htm?/scripting/vbscript/doc/vsfc
tDateDiff.htm
For assistance, post to one of the following groups.
news:microsoft.public.scripting.vbscript
news:microsoft.public.scripting.wsh
BTW, did you know?... There is a group (alt.msdos.batch.NT) which deals
specifically with NT (NT5=2000) related batch discussions. Please ask NT
related questions there.
--
Todd Vargo (body of message must contain my name to reply by email)
NTDOS has many unfortunate (incompatible) differences with MSDOS so
I've no idea whether this demo will work for you but the method
of using AWK for this will work (probably could be made simpler
using those NT extensions you mention).
-------------------------TIMER.BAT
@ECHO OFF
::
:: start timer
SET F=substr($0,7,2)+60*(substr($0,4,2)+60*substr($0,1,2))
ECHO EXIT |%COMSPEC% /K PROMPT $T$_ |AWK "NR==2{print \"EXIT \"%F%}">T0
::
:: next 2 lines are a demo... replace with code to time
ECHO TIMER STARTED. PRESS ANY KEY TO SAMPLE.
PAUSE>NUL
::
:: stop timer
TYPE T0 |%COMSPEC% /K PROMPT $T$_|AWK "NR==2{n=%F%}NR==3{print \"SET F=\"n-$2}">$.BAT
CALL $.BAT
FOR %%_ IN ($.BAT T0) DO DEL %%_
::
:: seconds elapsed in environment variable %F%
ECHO TIME ELAPSED=%F% SECONDS
-------------------------TIMER.BAT
The current time is read using the PROMPT command with $T and sent
to a 1st AWK script which converts that time into the number of
seconds (since 00:00:00.00). This is saved in a temporary file
and the code you wish to time is then executed. When the code
has finished the time is sampled again and sent along with
the original into a last AWK script that calculates the
difference between them in seconds.
To display the time difference in the format hh:mm:ss simply
extend the 2nd AWK script to convert the difference (n-$2)
into that. You might also want to seperate the AWK scripts
into files (or generate the files from the batch) so that
they are easier to maintain. This will NOT deal properly
with the end time wrapping past midnight but it's very easy to
sort that out: the main thing is to get it going in NT first anyhow....
If you don't have AWK you can download it from simtel archive
(ftp://ftp.simtel.net, or just do a web-search for AWK+NT...)
If you've never programmed AWK before it is a good investment
to learn, it is a very powerful standard administrators tool and
versions can be found for almost any OS, it even has it's own
dedicated NG; comp.lang.awk.
Bye,
$L
>
>Regards
>Peter
>
oblong
"Peter Blatt" <pet...@redseven.com> wrote in message
news:3b503cef$0$19083$9b62...@news.freenet.de...
> dotime -start
> ...
> ...do something
> ...
> echo dotime -showelapsed
>
> MS-DOS extensions for WinNT/Win2000 and external programs can be used
1) using MS-DOS prompt feature:
you can set prompt to contain time (prehaps only time),
see exact syntax under "help prompt".
Thus you can run command.com to write the actual time (before and after
the programruns) to a file.
All you need to finish is some program which can subtract the two times
and print the difference.
I'd use awk but it may not be the easiest way for you.
2) If you install cygwin (www.cygwin.com), you'll get program
time.exe which does exactly what you want.
Instead of running
pgm p1 p2 ...
you run
time pgm p1 p2 ...
and the pgm is run and when in ends, the program time prints
the time the pgm run.
This is not one program, it's some DLL, plenty of exe files, but
it's ready to help then.
HTH,
Stepan