home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / timer / milli / readme < prev    next >
Encoding:
Text File  |  1994-06-12  |  3.0 KB  |  73 lines

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