ORCA-C/C.Samples/Benchmarks/FIB.cc
Stephen Heumann ab975b611c Add C samples.
These are the samples from ORCA/C 2.1.0, converted to LF line endings.
2023-04-23 18:34:34 -05:00

47 lines
954 B
C++

/***************************************************************
*
* Fibonacci
*
* Recursively computes Fibonacci numbers to test the speed of
* function calls.
*
* To get the best performance from the desktop development
* environment, be sure and turn debugging off from the
* Compile Dialog. Use the Compile command from the Run menu
* to get the compile dialog.
*
****************************************************************/
#pragma keep "FIB"
#pragma optimize -1
#pragma lint -1
#include <stdio.h>
#define NTIMES 10 /* # iterations */
#define NUMBER 23 /* largest Fib # smaller than 32767 */
int Fibonacci(int x)
{
if (x > 2)
return Fibonacci(x-1)+Fibonacci(x-2);
else
return 1;
}
int main (void)
{
int value;
unsigned i;
printf("%d iterations:\n", NTIMES);
for (i = 0; i < NTIMES; ++i)
value = Fibonacci(NUMBER);
printf("Fibonacci(%d) = %d\n", NUMBER, value);
return 0;
}