home *** CD-ROM | disk | FTP | other *** search
- Dean Pentcheff
- Department of Integrative Biology
- University of California at Berkeley
- dean@violet.berkeley.edu
-
- The code here provides PC programs with a millisecond resolution timer. It
- is entirely based on "tctimer" 1.0 by Richard S. Sadowsky (released to the
- public domain 8/10/88) which, in turn, is based on "tptime" by Brian Foley
- and Kim Kokkonen of TurboPower Software (also public domain). I have
- slightly rewritten the code to conform to C language conventions (in tctimer,
- results were passed as argument pointers rather than function returns). In
- this version, elapsedtime() returns a time in seconds rather than
- milliseconds, saving a floating point division by 1000.0.
-
- These routines reprogram the timer chip, so they probably won't work if your
- program does the same. Other than that, there should be no incompatibility
- problems. They do not interfere with Turbo's sound() and nosound()
- functions.
-
- I've tested these under Turbo C 2.0. Note that the file tctimer.c must be
- separately compiled with the standalone "tcc" compiler since it uses inline
- assembly. Attempting to compile it under "tc" will result in compile-time
- error messages.
-
- The routine "initializetimer()" MUST be called first to reset the timer. The
- calling program MUST also call "restoretimer()" before exiting to reset the
- timer to its original state.
-
-
- The following routines are included (see testtimer.c for examples):
-
- /*Reprogram the timer chip to allow 1 microsecond resolution*/
- void initializetimer(void);
-
- /*Read the timer with 1 microsecond resolution*/
- long readtimer(void);
-
- /*Calculate time elapsed (in seconds) between Start and Stop*/
- double elapsedtime(long start, long stop);
-
- /*Restore the timer chip to its normal state*/
- void restoretimer(void);
-
-
- Limitations
- -----------
- Because long integers are used to represent time, TCTIMER cannot be used to
- time events longer than about 60 minutes:
-
- 4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
- / 1,193,181 (timer resolution in counts/second)
- ---------------
- 3,599
- / 60 (seconds/minute)
- -------
- 59.9 minutes
-
- This should hardly be a problem, however, since an event longer than an hour
- presumably doesn't need to be timed with 1-microsecond accuracy anyway.
-
- Also note that the process of reading the time takes time. Hence, results of
- timing very short events will be skewed by the overhead of reading the timer.
- The following table shows the time measured between two calls to ReadTimer,
- one right after the other.
-
- Toshiba 1000 (4.77MHz 8088) 125 microseconds (tctimer)
- ATT 6300 (8MHz 8086) 53 " (tctimer)
- Deskpro 286 (8MHz 80286) 35 " (tctimer)
- Sperry IT (7.1MHz 286, 0 wait) 32 " (tctimer)
- IBM PS/2 model 50 25 " (tctimer)
- PC Designs GV386 (16MHz) 27 " (tctimer)
- PC Source Standard 286 (10MHz) 21 " (these routines)
-