home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1989 / 02 / vose&wel.asc < prev    next >
Text File  |  1989-01-04  |  2KB  |  87 lines

  1. _A Benchmark Apologia_
  2. by G. Michael Vose and Dave Weil
  3.  
  4. [EXAMPLE 1] 
  5.  
  6. /*   The floating point arithmetic benchmark 
  7.  *   does repeated multiplications & divisions in a loop that is 
  8.  *   large enough to make the looping time insignificant. This 
  9.  *   program is from the August 1983 issue of Byte magazine. 
  10. */ 
  11. #include <stdio.h> 
  12.  
  13. #define CONST1 3.141597E0 
  14. #define CONST2 1.7839032E4 
  15. #define COUNT 50000 
  16.  
  17. main () 
  18.         { 
  19.         double a, b, c; 
  20.         unsigned int i; 
  21.  
  22.         time_0(); 
  23.  
  24.         a = CONST1; 
  25.         b = CONST2; 
  26.  
  27.         for( i = 0; i < COUNT; ++i) 
  28.                 { 
  29.                 c = a * b; 
  30.                 c = c / a; 
  31.                 c = a * b; 
  32.                 c = c / a; 
  33.                 c = a * b; 
  34.                 c = c / a; 
  35.                 c = a * b; 
  36.                 c = c / a; 
  37.                 c = a * b; 
  38.                 c = c / a; 
  39.                 c = a * b; 
  40.                 c = c / a; 
  41.                 c = a * b; 
  42.                 c = c / a; 
  43.                 } 
  44.         fprintf (stderr, "%d\n", time_n()); 
  45.         } 
  46.  
  47.  
  48.  
  49.  
  50. [EXAMPLE 2] 
  51.  
  52. /*      The Fibonacci benchmark tests recursive procedure calls 
  53. */ 
  54.  
  55. #include <stdio.h> 
  56.  
  57. #define NTIMES  34 
  58. #define NUMBER  24 
  59.  
  60. main() 
  61.         { 
  62.         int i; 
  63.         unsigned value, fib(); 
  64.  
  65.         time_0(); 
  66.  
  67.         printf ("%d iterations: ", NTIMES); 
  68.  
  69.         for( i = 1; i <= NTIMES; i++ ) 
  70.                 value = fib(NUMBER); 
  71.  
  72.         printf ("\n"); 
  73.  
  74.         fprintf (stderr, "%d\n", time_n()); 
  75.         } 
  76. unsigned fib(x) 
  77. int x; 
  78.         { 
  79.         if( x > 2 ) 
  80.                 return (fib(x-1) + fib(x - 2)); 
  81.         else 
  82.                 return (1); 
  83.         } 
  84.  
  85.  
  86.  
  87.