29 Ekim 2008 Çarşamba

Recursive fibonacci Case Study

In that post i'm going show u a test that i made about recursive calls in Python compared to other languages. The tests used are Python,Python C extension and Java. I always heard that using recursive calls in Python is not very wise, that time i decided to discover it myself. Well i run the 3 programs to find finacci 40. number and got their times with time command in F9. Tests do not claim anything so do not bother me with garbage :) Here they are :

Python
[makkalot@localhost pyalgorithm]$ time python py_fibo.py 40
The result is : 102334155

real 6m32.110s
user 6m22.153s
sys 0m0.519s



Python_Ex :
[makkalot@localhost fibo]$ time python ex_fibo.py rec 40
The recursive result is : 102334155

real 0m3.039s
user 0m2.902s
sys 0m0.017s



Java
[makkalot@localhost bin]$ time java sorts.FiboMan rec 40
The recursive result is 102334155

real 0m4.053s
user 0m2.755s
sys 0m0.095s

Conclusion : The results suprised me a little bit. I knew that Python as a recursive language is slow but the time above is a disaster. Therefore i know now if i need sth recursive in Python i will write it as a C extension. The java also suprised me because its time was very close to C extension. Those Java guys are getting better, maybe JavaFX may make to become a Java programmer :)

Btw, here are the codes :
Python : Link
C extension : Link
Java : Link

Hiç yorum yok: