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

  1.  
  2.     1   /* benchfn - benchmark for function calls
  3.     2    * Thomas Plum, Plum Hall Inc, 609-927-3770
  4.     3    * Let  T  be the execution time in milliseconds
  5.     4    * Then  average time per operator  =  T/major  usec
  6.     5    * (Because the inner loop has exactly 1000 operations)
  7.     6    */
  8.     7   #include <stdio.h>
  9.     8   int dummy = 0;
  10.     9   
  11.    10   /* f3 - lowest level function
  12.    11    * Put this in separate source file if compiler detects and optimizes
  13.    12    * useless code
  14.    13    */
  15.    14   f3() { }
  16.    15   
  17.    16   f2() { f3();f3();f3();f3();f3();f3();f3();f3();f3();f3();} /* 10 */
  18.    17   f1() { f2();f2();f2();f2();f2();f2();f2();f2();f2();f2();} /* 10 */
  19.    18   f0() { f1();f1();f1();f1();f1();f1();f1();f1();f1();} /* 9 */
  20.    19   
  21.    20   main(ac, av)
  22.    21           int ac;
  23.    22           char *av[];
  24.    23           {
  25.    24           long d, major, atol();
  26.    25   
  27.    26           major = atol(av[1]);
  28.    27           printf("executing %ld iterations\n", major);
  29.    28           for (d = 1; d <= major; ++d)
  30.    29                   f0(); /* executes 1000 calls */
  31.    30           printf("dummy=%d\n", dummy);
  32.    31           }
  33.