All pastes #352543 Raw Edit

Untitled

public text v1 · immutable
·published 2007-02-12 22:05 UTC
rendered paste body
So I create a file named fib.groovy:

def fib(int n) {
if(n <= 1) return 1;
else return fib(n-1) + fib(n-2);
}

s = System.currentTimeMillis();
fib(30);
System.out.println(System.currentTimeMillis()-s);

I compile it:

sh bin/groovyc fib.groovy

I run it:

sh bin/groovy fib
20450

Now I create a file fib.java

public class fib {
static int fib(int n) {
if(n <= 1) return 1;
else return fib(n-1) + fib(n-2);
}

public static void main(String[] args)
{
long s = System.currentTimeMillis();
fib(30);
System.out.println(System.currentTimeMillis()-s);
}
}

I compile it

javac fib.java

I run it

java fib
19

So 19 milli seconds -vs- 20 seconds.