home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_04 / v6n4044a.txt < prev    next >
Text File  |  1989-09-28  |  2KB  |  41 lines

  1.  
  2.     1   /* benchreg - benchmark for  register  integers
  3.     2    * Thomas Plum, Plum Hall Inc, 609-927-3770
  4.     3    * If machine traps overflow, use an  unsigned  type
  5.     4    * Let  T  be the execution time in milliseconds
  6.     5    * Then  average time per operator  =  T/major  usec
  7.     6    * (Because the inner loop has exactly 1000 operations)
  8.     7    */
  9.     8   #define STOR_CL register
  10.     9   #define TYPE int
  11.    10   #include <stdio.h>
  12.    11   main(ac, av)
  13.    12           int ac;
  14.    13           char *av[];
  15.    14           {
  16.    15           STOR_CL TYPE a, b, c;
  17.    16           long d, major, atol();
  18.    17           static TYPE m[10] = {0};
  19.    18   
  20.    19           major = atol(av[1]);
  21.    20           printf("executing %ld iterations\n", major);
  22.    21           a = b = (av[1][0] - '0');
  23.    22           for (d = 1; d <= major; ++d)
  24.    23                   {
  25.    24                   /* inner loop executes 1000 selected operations */
  26.    25                   for (c = 1; c <= 40; ++c)
  27.    26                           {
  28.    27                           a = a + b + c;
  29.    28                           b = a >> 1;
  30.    29                           a = b % 10;
  31.    30                           m[a] = a;
  32.    31                           b = m[a] - b - c;
  33.    32                           a = b == c;
  34.    33                           b = a | c;
  35.    34                           a = !b;
  36.    35                           b = a + c;
  37.    36                           a = b > c;
  38.    37                           }
  39.    38                   }
  40.    39           printf("a=%d\n", a);
  41.    40           }