home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / timer1.h < prev    next >
C/C++ Source or Header  |  1985-08-29  |  3KB  |  96 lines

  1. /* timer1.h - this file is to be included at the front of each
  2.  * timing sample file.
  3.  * Note: variables visible to the sample file all start with "t_";
  4.  * macro names all start with "T_", to avoid name conflicts.
  5.  */
  6. #include <stdio.h>
  7.  
  8. #define void int    /* remove if compiler supports  void  */
  9. typedef int bool;
  10. #define T_NO  0
  11. #define T_YES 1
  12. #define T_MAXITER  10000000
  13.  
  14. #define T_SKIP 0
  15. #define T_NOASST 1
  16. #define T_REGASST 2
  17. #define T_DBLASST 3
  18. #define T_LOOPDOWN(a, b) for (a = (b)+1; --a > 0;  )
  19. #define DO_SKIP(S) \
  20.     t_s=S; \
  21.     t_type = T_SKIP; \
  22.     begintim(0); \
  23.     if (0) { 
  24. #define DO_STMT(S) \
  25.     t_s=S; \
  26.     t_type = T_NOASST; \
  27.     if (t_sample[t_try] < t_minsam) { \
  28.     begintim(0); \
  29.     T_LOOPDOWN(t_major, t_majrlim) T_LOOPDOWN(t_minor, t_minrlim)
  30. #define DO_FEXPR(S) \
  31.     t_s=S; \
  32.     t_type = T_DBLASST; \
  33.     if (t_sample[t_try] < t_minsam) { \
  34.     begintim(0); \
  35.     T_LOOPDOWN(t_major, t_majrlim) T_LOOPDOWN(t_minor, t_minrlim)  t_dbl = 
  36. #define DO_IEXPR(S) \
  37.     t_s=S; \
  38.     t_type = T_REGASST; \
  39.     if (t_sample[t_try] < t_minsam) { \
  40.     begintim(0); \
  41.     T_LOOPDOWN(t_major, t_majrlim) T_LOOPDOWN(t_minor, t_minrlim)  t_reg = 
  42. #define OD ;} endtim(0);  ++t_try;
  43.                                                                                             /*
  44. .PE
  45. .PS 50
  46. /* external references */
  47. extern char *t_s;            /* description of this try */
  48. extern long t_reps;            /* number of samples this iteration */
  49. extern short t_try;            /* which trial number is being done next */
  50. extern short t_type;        /* selection of timing method */
  51. extern double t_minsam;        /* desired minimum samples */
  52. extern double t_sample[];    /* actual samples for each try */
  53. extern char *t_title[];        /* array of descriptions for printout */
  54. extern short t_size[];        /* array of code sizes in bytes */
  55. extern double t_ctime[];    /* array of actual times */
  56.  
  57. /* static (internal) definitions */
  58. static double t_dbl = 0;        /* target for forced double assigns */
  59. static unsigned t_majrlim = 0;    /* major loop limit */
  60. static unsigned t_major = 0;    /* major loop variable */
  61. static unsigned t_minrlim = 0;    /* minor loop limit */
  62. static unsigned t_minor = 0;    /* minor loop variable */
  63. static void t_timeall();
  64. main()
  65.     {
  66.     bool more;
  67.     short i;
  68.  
  69.     t_reps = 1;
  70.     do
  71.         {
  72.         t_try = 0;
  73.         if (t_reps <= 10000)
  74.             {
  75.             t_minrlim = t_reps;
  76.             t_majrlim = 1;
  77.             }
  78.         else
  79.             {
  80.             t_minrlim = 10000;
  81.             t_majrlim = t_reps / 10000;
  82.             }
  83.         t_timeall();
  84.         t_reps *= 10;
  85.         more = T_NO;
  86.         for (i = 0; i < t_try; ++i)
  87.             if (t_sample[i] < t_minsam)
  88.                 more = T_YES;
  89.         } while (more && t_reps <= T_MAXITER);
  90.     report();
  91.     }
  92. static void t_timeall()
  93.     {
  94.     register int t_reg;        /* target for forced assigns */
  95.     /* ... USER'S FUNCTION CONTINUES HERE ... */
  96.