Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

subtracting two times/time measurement lap

2 views
Skip to first unread message

Peter Blatt

unread,
Jul 14, 2001, 8:37:03 AM7/14/01
to
Is there a way of measuring the time period between two certain points and showing it in the format hh:mm:ss ?
I am thinking of a command like

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

Andrew J Kennedy

unread,
Jul 14, 2001, 9:22:12 AM7/14/01
to
This should do the job. It just returns the time difference in seconds.


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

Bernd Blaauw

unread,
Jul 14, 2001, 12:47:18 PM7/14/01
to
have a look at www.jpsoft.com

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...

Dr John Stockton

unread,
Jul 14, 2001, 1:14:59 PM7/14/01
to
JRS: In article <3b503cef$0$19083$9b62...@news.freenet.de>, seen in
news:comp.os.msdos.misc, Peter Blatt <pet...@redseven.com> wrote at Sat,
14 Jul 2001 12:37:03 :-

>Is there a way of measuring the time period between two certain points and
>showing it in the format hh:mm:ss ?

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)

Frank-Peter Schultze

unread,
Jul 15, 2001, 8:47:22 AM7/15/01
to
"Peter Blatt" <pet...@redseven.com> schrieb im Newsbeitrag news:3b503cef$0$19083$9b62...@news.freenet.de...

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

Rik D'haveloose

unread,
Jul 14, 2001, 2:45:57 PM7/14/01
to
Peter Blatt wrote:
>
> Is there a way of measuring the time period between two certain points and showing it in the format hh:mm:ss ?
> I am thinking of a command like
==8<
> dotime -start
> ...
> ...do something
> ...
> echo dotime -showelapsed
>
> MS-DOS extensions for WinNT/Win2000 and external programs can be used

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


Todd Vargo

unread,
Jul 16, 2001, 1:46:59 AM7/16/01
to

"Peter Blatt" <pet...@redseven.com> wrote in message
news:3b503cef$0$19083$9b62...@news.freenet.de...

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)

laura fairhead

unread,
Jul 16, 2001, 1:09:00 PM7/16/01
to

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

unread,
Jul 17, 2001, 1:29:42 PM7/17/01
to
would the time span ever be over 24 hours?
you might be best served (and save yourself the headache of a lot of
grunt-work math) by making the time & date a serial number. the difference
between the two could then be handled appropriately.
i could whip up something quickly for you if you so desired, gratis; i
wouldn't recommend doing it just with a "clever" batch file though.

oblong

"Peter Blatt" <pet...@redseven.com> wrote in message
news:3b503cef$0$19083$9b62...@news.freenet.de...

Stepan Kasal

unread,
Jul 23, 2001, 7:03:02 AM7/23/01
to
On 14 Jul 2001 12:37:03 GMT, Peter Blatt <pet...@redseven.com> wrote:
> Is there a way of measuring the time period between two certain points
> and showing it in the format hh:mm:ss ?

> 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

0 new messages