home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05066a < prev    next >
Text File  |  1991-10-15  |  2KB  |  34 lines

  1. /*========================== my_timer.h ===================================*/
  2. /* "my_timer.h" A non-standard header file that defines the function-like  */
  3. /*  preprocessor macros START(desc) and STOP(); use to measure the         */
  4. /*  performance of coding alternatives; suitable for use with any ANSI C   */
  5. /*  compiler; software adapted from the book, ENCYCLOPEDIA C, by           */
  6. /*  R.Radcliffe (SYBEX/1991), Fig 5.1, Pg 234                              */
  7. /*                                                                         */
  8. /*  NOTE:       1)  #define MY_TIMER to activate START() and STOP          */
  9. /*              2)  re #define NTIMES as necessary - see my_timer.c        */
  10. /*              3)  CLK_TCK may be replaced with CLOCKS_PER_SEC            */
  11. /*                                                                         */
  12. /*=========================================================================*/
  13. #if !defined(MY_TIMER_DEFINED)
  14. #   define NTIMES 30000
  15. #   if defined(MY_TIMER)
  16. #       include <stdio.h>
  17. #       include <time.h>
  18.         clock_t  stop_tick, start_tick;
  19. #       define START(desc) printf("\n\nfor : %s",#desc);\
  20.             start_tick = clock() + (clock_t)1;\
  21.             while (start_tick > clock());\
  22.             start_tick = clock();
  23. #       define TICKS  (stop_tick - start_tick)
  24. #       define STOP   stop_tick  = clock();\
  25.             printf("\ntime: %7.2lf sec  stop: %ld  start: %ld\n",\
  26.                 (double)TICKS/(double)CLK_TCK, stop_tick, start_tick);
  27. #       define MY_TIMER_DEFINED
  28. #   else
  29. #       define START(desc)
  30. #       define STOP
  31. #   endif
  32. #endif
  33. /*=========================== my_timer.h ==================================*/
  34.