home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05066b < prev    next >
Text File  |  1992-02-23  |  2KB  |  36 lines

  1. /*=========================== my_timer.c ==================================*/
  2. /*  A test program using "my_timer.h" to time the performance difference   */
  3. /*  between using the function-like macro isdigit() or the corresponding   */
  4. /*  runtime library function isdigit(); if the preprocessor object-like    */
  5. /*  macro MY_TIMER is defined, the START and STOP macros are invoked;      */
  6. /*  otherwise, no such code is generated, and no runtime performance       */
  7. /*  penalty is imposed - much like using assertions - NDEBUG and assert(); */
  8. /*                                                                         */
  9. /*  Inspect the intermediate file (*.i) generated by the preprocessor to   */
  10. /*  see the effects of using the START() and STOP macros; use compiler     */
  11. /*  option -P for Microsoft C; run the CPP.EXE utility Borland C;          */
  12. /*                                                                         */
  13. /*  NOTE: Remember to #define MY_TIMER (-DMY_TIMER on the command-line)    */
  14. /*  before you #include "my_timer.h"                                       */
  15. /*=========================================================================*/
  16. #include <ctype.h>
  17.  
  18. #define MY_TIMER            /* This activates the timer code */
  19. #include "my_timer.h"
  20.  
  21. void main( void) {
  22.     char ch = '9';
  23.     int i, is;
  24.  
  25.     START(default function-like macro timing);
  26.     for (i=0; i<NTIMES; i++) is = isdigit(ch);
  27.     STOP;
  28.  
  29.     #undef isdigit
  30.  
  31.     START(alternate function timing);
  32.     for (i=0; i<NTIMES; i++) is = isdigit(ch);
  33.     STOP;
  34.     }
  35. /*=========================== my_timer.c ==================================*/
  36.