In order to run a few benchmarks on my newly installed 13.04, I wrote the below fibonacci script in python. It basically accepts a number and starts crunching fibonacci numbers that many times:
#!/usr/bin/python
import time
from time import time
def fibo(n):
a,b,i=0,1,0
while i<n:
#print b
a,b = b,b+a
i+=1
if __name__ == "__main__":
s=time()
fibo(1000000)
print round((time()-s)*1000,0),"ms"
However, when the fibo() function is called with 1 million as parameter, the python seems to hang. While, this similar code in java runs instantly:
class fibonacci
{
private static void fibo(int n)
{
int a=0,b=1,i=0;
while( i<n)
{
//print b
int t=a;
a=b;
b=b+t;
i++;
}
}
public static void main(String[] args)
{
float s=System.currentTimeMillis();
fibo(1000000);
System.out.println( (System.currentTimeMillis()-s) + "ms");
}
}
What is the reason for this? Is python inherently that slow or is something wrong with my raring installation ?