home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / tctimer.doc < prev    next >
Text File  |  1990-09-29  |  3KB  |  86 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. ADDITIONAL FILES ADDED 9/30/90:
  15.         xtimer.c        - modified version of tctimer.c for Microsoft C 5.x
  16.         mytimer.asm     - contains the inline assembly code from tctimer.c
  17.                           converted to MASM 5.x
  18. These modifications allow the timer to be compiled under MSC 5.x which does
  19. not support inline assembly.
  20.                         David Burki
  21.  
  22. Overview
  23. ------------------------------------------------------------------------------
  24. One problem commonly faced when trying to run benchmarks on a PC is that, by
  25. default, the system clock is accurate only to 1/18th of a second. The TCTIMER
  26. unit provides a simple and convenient means of timing events with microsecond
  27. Unless your program is working with the timer chip at a very low level, no
  28. incompatibilities should arise, nor should the performance of your program
  29. change.
  30.  
  31. Using TCTIMER
  32. ------------------------------------------------------------------------------
  33. Before using any other TCTimer routines, initializetimer() must be called.
  34. Then, events are timed by calling readtimer when you are ready to start/stop
  35. timing. Any program that calls initializetimer() must call restoretimer()
  36. before terminating.  See TESTTIME.C for a sample use of the TCTIMER routines.
  37.  
  38. TCTIMER includes the following routines:
  39.  
  40.  
  41. long readtimer(void);
  42. /*Read the timer with 1 microsecond resolution*/
  43.  
  44. void elapsedtime(long start, long stop, double *result);
  45. /*Calculate time elapsed (in milliseconds) between Start and Stop*/
  46.  
  47.  
  48. void initializetimer(void);
  49. /*Reprogram the timer chip to allow 1 microsecond resolution*/
  50.  
  51. void restoretimer(void);
  52. /*Restore the timer chip to its normal state*/
  53.  
  54. InitializeTimer must be executed before any other TCTIMER routines are called.
  55. RestoreTimer must be called before the program ends.  Failure to call
  56. initializetimer will result in incorrect results and failure to call
  57. restoretimer may result in chaos.
  58.  
  59. Limitations
  60. -----------
  61. Because long integers are used to represent time, TCTIMER cannot be used to
  62. time events longer than about 60 minutes:
  63.  
  64.    4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
  65.  /     1,193,181 (timer resolution in counts/second)
  66.  ---------------
  67.            3,599
  68.          /    60 (seconds/minute)
  69.          -------
  70.             59.9 minutes
  71.  
  72. This should hardly be a problem, however, since an event longer than an hour
  73. presumably doesn't need to be timed with 1-microsecond accuracy anyway.
  74.  
  75. Also note that the process of reading the time takes time. Hence, results of
  76. timing very short events will be skewed by the overhead of reading the timer.
  77. The following table shows the time measured between two calls to ReadTimer,
  78. one right after the other.
  79.  
  80.   Toshiba 1000 (4.77MHz 8088)    125 microseconds
  81.   ATT 6300 (8MHz 8086)            53     "
  82.   Deskpro 286 (8MHz 80286)        35     "
  83.   Sperry IT (7.1MHz 286, 0 wait)  32     "
  84.   IBM PS/2 model 50               25     "
  85.   PC Designs GV386 (16MHz)        27     "
  86.