home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1989
/
02
/
vose&wel.asc
< prev
next >
Wrap
Text File
|
1989-01-04
|
2KB
|
87 lines
_A Benchmark Apologia_
by G. Michael Vose and Dave Weil
[EXAMPLE 1]
/* The floating point arithmetic benchmark
* does repeated multiplications & divisions in a loop that is
* large enough to make the looping time insignificant. This
* program is from the August 1983 issue of Byte magazine.
*/
#include <stdio.h>
#define CONST1 3.141597E0
#define CONST2 1.7839032E4
#define COUNT 50000
main ()
{
double a, b, c;
unsigned int i;
time_0();
a = CONST1;
b = CONST2;
for( i = 0; i < COUNT; ++i)
{
c = a * b;
c = c / a;
c = a * b;
c = c / a;
c = a * b;
c = c / a;
c = a * b;
c = c / a;
c = a * b;
c = c / a;
c = a * b;
c = c / a;
c = a * b;
c = c / a;
}
fprintf (stderr, "%d\n", time_n());
}
[EXAMPLE 2]
/* The Fibonacci benchmark tests recursive procedure calls
*/
#include <stdio.h>
#define NTIMES 34
#define NUMBER 24
main()
{
int i;
unsigned value, fib();
time_0();
printf ("%d iterations: ", NTIMES);
for( i = 1; i <= NTIMES; i++ )
value = fib(NUMBER);
printf ("\n");
fprintf (stderr, "%d\n", time_n());
}
unsigned fib(x)
int x;
{
if( x > 2 )
return (fib(x-1) + fib(x - 2));
else
return (1);
}