home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / turbo_c / tctimer.arc / TCTIMER.DOC < prev    next >
Text File  |  1988-08-10  |  3KB  |  78 lines

  1. TCTIMER - Routines for high-resolution timing of events for Turbo C
  2. ------------------------------------------------------------------------
  3.  
  4. Richard S. Sadowsky
  5. 8/10/88
  6. Version 1.0
  7. Released to the public domain
  8.  
  9. BASED ON TPTIME.ARC
  10.  
  11. which was written by Brian Foley and Kim Kokkonen of TurboPower Software and
  12. released to the public domain.
  13.  
  14. Overview
  15. ------------------------------------------------------------------------------
  16. One problem commonly faced when trying to run benchmarks on a PC is that, by
  17. default, the system clock is accurate only to 1/18th of a second. The TCTIMER
  18. unit provides a simple and convenient means of timing events with microsecond
  19. Unless your program is working with the timer chip at a very low level, no
  20. incompatibilities should arise, nor should the performance of your program
  21. change.
  22.  
  23. Using TCTIMER
  24. ------------------------------------------------------------------------------
  25. Before using any other TCTimer routines, initializetimer() must be called.
  26. Then, events are timed by calling readtimer when you are ready to start/stop
  27. timing. Any program that calls initializetimer() must call restoretimer()
  28. before terminating.  See TESTTIME.C for a sample use of the TCTIMER routines.
  29.  
  30. TCTIMER includes the following routines:
  31.  
  32.  
  33. long readtimer(void);
  34. /*Read the timer with 1 microsecond resolution*/
  35.  
  36. void elapsedtime(long start, long stop, double *result);
  37. /*Calculate time elapsed (in milliseconds) between Start and Stop*/
  38.  
  39.  
  40. void initializetimer(void);
  41. /*Reprogram the timer chip to allow 1 microsecond resolution*/
  42.  
  43. void restoretimer(void);
  44. /*Restore the timer chip to its normal state*/
  45.  
  46. InitializeTimer must be executed before any other TCTIMER routines are called.
  47. RestoreTimer must be called before the program ends.  Failure to call
  48. initializetimer will result in incorrect results and failure to call
  49. restoretimer may result in chaos.
  50.  
  51. Limitations
  52. -----------
  53. Because long integers are used to represent time, TCTIMER cannot be used to
  54. time events longer than about 60 minutes:
  55.  
  56.    4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
  57.  /     1,193,181 (timer resolution in counts/second)
  58.  ---------------
  59.            3,599
  60.          /    60 (seconds/minute)
  61.          -------
  62.             59.9 minutes
  63.  
  64. This should hardly be a problem, however, since an event longer than an hour
  65. presumably doesn't need to be timed with 1-microsecond accuracy anyway.
  66.  
  67. Also note that the process of reading the time takes time. Hence, results of
  68. timing very short events will be skewed by the overhead of reading the timer.
  69. The following table shows the time measured between two calls to ReadTimer,
  70. one right after the other.
  71.  
  72.   Toshiba 1000 (4.77MHz 8088)    125 microseconds
  73.   ATT 6300 (8MHz 8086)            53     "
  74.   Deskpro 286 (8MHz 80286)        35     "
  75.   Sperry IT (7.1MHz 286, 0 wait)  32     "
  76.   IBM PS/2 model 50               25     "
  77.   PC Designs GV386 (16MHz)        27     "
  78.