benchmarks.larceny/src/fib.java
raw| 1 | /* FIB -- A classic benchmark, computes fib(30) inefficiently. */ |
| 2 | |
| 3 | class fib { |
| 4 | |
| 5 | static int fib (int n) |
| 6 | { |
| 7 | if (n < 2) |
| 8 | return n; |
| 9 | else |
| 10 | return fib (n-1) + fib (n-2); |
| 11 | } |
| 12 | |
| 13 | public static void main (String args[]) |
| 14 | { |
| 15 | int i; |
| 16 | int result = 0; |
| 17 | |
| 18 | for (i=0; i<50; i++) |
| 19 | result = fib (30); |
| 20 | |
| 21 | if (result != 832040) |
| 22 | System.out.println ("*** wrong result ***"); |
| 23 | } |
| 24 | |
| 25 | } |