delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/25/05:32:03

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Calculating Time-lapse (time taken between calculations)
Date: 24 Oct 1997 23:43:06 GMT
Organization: Oxford University, England
Lines: 43
Message-ID: <62rbqa$933$1@news.ox.ac.uk>
References: <62ra8g$hch$1 AT news DOT interlog DOT com>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Fri, 24 Oct 97 23:24:56 GMT in comp.os.msdos.djgpp Gautam N. Lad
(gautam AT interlog DOT com) wrote: 

: - Start the Stop-Watch
: 	- Calculate information, and process it
: - Stop the Stop-Watch

: How do I do this in C?

: Oh, I'm using DJGPP and Allegro v2.2.

In C you could try using the uclock() function, but apparently this is
unreliable in Windows 95. There is also the clock() function, but this
doesn't have good resolution. Various timeing functions give an accuracy in
centiseconds; again, this might not be enough for your purposes.

Since you're using Allegro, you could install your own timer callback,
triggered frequently, which increments a global variable.

Using uclock, clock or Allegro, to start your stopwatch, read the value of
the variable. To `stop' it, read the value again, and the time elapsed is the
difference between the two values. If you are really looking for high
accuracy, you might like to also do a dummy run, starting the stopwatch and
immediately stopping it, to check what the overhead of doing so is. Caching
issues may make this slightly unreliable as well though, and for nearly all
things you might be timing the overhead is pretty irrelevant anyway. By far
the best way to time a routine is to do the routine many times, read the time
taken to do so, and divide by the number of times you ran the routine;
however for small routines or those which do not access much data, caching
can skew the results.

The accuracy available with Allegro's timers depends, again, on whether Win95
is being used; if so, Allegro's timers run at a maximum rate of 1/200 of a
second (5 msec). Otherwise, they're somewhat faster; I'm not sure by how
much.

Also note that Allegro's timers interfere with some standard timing functions
(e.g. uclock, apparently); best not to mix them...

-- 
Regards,

george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019