home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / benches.d < prev    next >
Text File  |  1985-11-26  |  5KB  |  194 lines

  1. ###benchlng.c
  2. /* benchlng - benchmark for  long  integers 
  3.  * Thomas Plum, Plum Hall Inc, 609-927-3770
  4.  * If machine traps overflow, use an  unsigned  type 
  5.  * Let  T  be the execution time in milliseconds
  6.  * Then  average time per operator  =  T/major  usec
  7.  * (Because the inner loop has exactly 1000 operations)
  8.  */
  9. #define STOR_CL auto
  10. #define TYPE long
  11. #include <stdio.h>
  12. main(ac, av)
  13.     int ac;
  14.     char *av[];
  15.     {
  16.     STOR_CL TYPE a, b, c;
  17.     long d, major, atol();
  18.     static TYPE m[10] = {0};
  19.  
  20.     major = atol(av[1]);
  21.     printf("executing %ld iterations\n", major);
  22.     a = b = 1;
  23.     for (d = 1; d <= major; ++d)
  24.         {
  25.         /* inner loop executes 1000 selected operations */
  26.         for (c = 1; c <= 40; ++c)
  27.             {
  28.             a = a + b + c;
  29.             b = a >> 1;
  30.             a = b % 10;
  31.             m[a] = a;
  32.             b = m[a] - b - c;
  33.             a = b == c;
  34.             b = a | c;
  35.             a = !b;
  36.             b = a + c;
  37.             a = b > c;
  38.             }
  39.         }
  40.     printf("a=%d\n", a);
  41.     }
  42. ###benchfn.c
  43. /* benchfn - benchmark for function calls
  44.  * Thomas Plum, Plum Hall Inc, 609-927-3770
  45.  * Let  T  be the execution time in milliseconds
  46.  * Then  average time per operator  =  T/major  usec
  47.  * (Because the inner loop has exactly 1000 operations)
  48.  */
  49. #include <stdio.h>
  50. extern int dummy = 0;
  51.  
  52. /* f3 - lowest level function
  53.  * Put this in separate source file if compiler detects and optimizes
  54.  * useless code
  55.  */
  56. f3() { }
  57.  
  58. f2() { f3();f3();f3();f3();f3();f3();f3();f3();f3();f3();} /* 10 */
  59. f1() { f2();f2();f2();f2();f2();f2();f2();f2();f2();f2();} /* 10 */
  60. f0() { f1();f1();f1();f1();f1();f1();f1();f1();f1();} /* 10 */
  61.  
  62. main(ac, av)
  63.     int ac;
  64.     char *av[];
  65.     {
  66.     long d, major, atol();
  67.  
  68.     major = atol(av[1]);
  69.     printf("executing %ld iterations\n", major);
  70.     for (d = 1; d <= major; ++d)
  71.         f0(); /* executes 1000 calls */
  72.     printf("dummy=%d\n", dummy);
  73.     }
  74. ###benchmul.c
  75. /* benchmul - benchmark for  int multiply
  76.  * Thomas Plum, Plum Hall Inc, 609-927-3770
  77.  * If machine traps overflow, use an  unsigned  type 
  78.  * Let  T  be the execution time in milliseconds
  79.  * Then  average time per operator  =  T/major  usec
  80.  * (Because the inner loop has exactly 1000 operations)
  81.  */
  82. #define STOR_CL auto
  83. #define TYPE int
  84. #include <stdio.h>
  85. main(ac, av)
  86.     int ac;
  87.     char *av[];
  88.     {
  89.     STOR_CL TYPE a, b, c;
  90.     long d, major, atol();
  91.     static TYPE m[10] = {0};
  92.  
  93.     major = atol(av[1]);
  94.     printf("executing %ld iterations\n", major);
  95.     a = b = 1;
  96.     for (d = 1; d <= major; ++d)
  97.         {
  98.         /* inner loop executes 1000 selected operations */
  99.         for (c = 1; c <= 40; ++c)
  100.             {
  101.             a = 3 *a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a; /* 25 * */
  102.             }
  103.         }
  104.     printf("a=%d\n", a);
  105.     }
  106. ###time-cmd.bat
  107. time <cr-lf
  108. %1 0
  109. time <cr-lf
  110. %1 10000
  111. time <cr-lf
  112. ###cr-lf.
  113.  
  114. ###run-all.sh
  115. c -o benchfn benchfn.c
  116. time-cmd benchfn >benchfn.out
  117. c -o benchmul benchmul.c
  118. time-cmd benchmul >benchmul.out
  119. c -o benchlng benchlng.c
  120. time-cmd benchlng >benchlng.out
  121. c -o benchsho benchsho.c
  122. time-cmd benchsho >benchsho.out
  123. c -o benchreg benchreg.c
  124. time-cmd benchreg >benchreg.out
  125. ###benchsho.c
  126. /* benchsho - benchmark for  short  integers 
  127.  * Thomas Plum, Plum Hall Inc, 609-927-3770
  128.  * If machine traps overflow, use an  unsigned  type 
  129.  * Let  T  be the execution time in milliseconds
  130.  * Then  average time per operator  =  T/major  usec
  131.  * (Because the inner loop has exactly 1000 operations)
  132.  */
  133. #define STOR_CL auto
  134. #define TYPE short
  135. #include <stdio.h>
  136. main(ac, av)
  137.     int ac;
  138.     char *av[];
  139.     {
  140.     STOR_CL TYPE a, b, c;
  141.     long d, major, atol();
  142.     static TYPE m[10] = {0};
  143.  
  144.     major = atol(av[1]);
  145.     printf("executing %ld iterations\n", major);
  146.     a = b = 1;
  147.     for (d = 1; d <= major; ++d)
  148.         {
  149.         /* inner loop executes 1000 selected operations */
  150.         for (c = 1; c <= 40; ++c)
  151.             {
  152.             a = a + b + c;
  153.             b = a >> 1;
  154.             a = b % 10;
  155.             m[a] = a;
  156.             b = m[a] - b - c;
  157.             a = b == c;
  158.             b = a | c;
  159.             a = !b;
  160.             b = a + c;
  161.             a = b > c;
  162.             }
  163.         }
  164.     printf("a=%d\n", a);
  165.     }
  166. ###mkwsl.bat
  167. c -dlistcs -dlo -o benchmul benchmul.c
  168. command /c time-cmd benchmul >benchmul.out
  169. c -dlistcs -dlo -o benchlng benchlng.c
  170. command /c time-cmd benchlng >benchlng.out
  171. c -dlistcs -dlo -o benchsho benchsho.c
  172. command /c time-cmd benchsho >benchsho.out
  173. c -dlistcs -dlo -o benchreg benchreg.c
  174. command /c time-cmd benchreg >benchreg.out
  175. c -dlistcs -dlo -o benchfn benchfn.c
  176. command /c time-cmd benchfn >benchfn.out
  177. ###mklattic.bat
  178. command /c lcc benchreg
  179. command /c time-cmd benchreg >benchreg.out
  180.  
  181. command /c lcc benchsho
  182. command /c time-cmd benchsho >benchsho.out
  183.  
  184. command /c lcc benchlng
  185. command /c time-cmd benchlng >benchlng.out
  186.  
  187. command /c lcc benchfn
  188. command /c time-cmd benchfn >benchfn.out
  189.  
  190. command /c lcc benchmul
  191. command /c time-cmd benchmul >benchmul.out
  192.  
  193. ###EOF
  194.