FYI.
bug: run fibonacci() for 10 times and it's much lower since the second time.
pypy:
Python 2.7.3 (87aa9de10f9c, Nov 24 2013, 20:57:21)
[PyPy 2.2.1 with GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``and nannanj to you as well''
applematoMacBook-Pro:pypy apple$ cat fib.py
#######################################################
import time
def fibonacci(n):
if n < 2:
return n
return fibonacci(n - 2) + fibonacci(n - 1)
for i in range(10):
t1 = time.time()
fibonacci(40)
print time.time() - t1
#########################################################
applematoMacBook-Pro:pypy apple$ pypy fib.py
6.90701889992
143.203435183
140.465835094
139.754812956
139.877434015
136.691543102
135.03269887
138.482003927
^CTraceback (most recent call last):
File "app_main.py", line 72, in run_toplevel
File "fib.py", line 10, in <module>
fibonacci(40)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
File "fib.py", line 6, in fibonacci
return fibonacci(n - 2) + fibonacci(n - 1)
KeyboardInterrupt
--
------------------------------------------------------------------------
华宏亮
Mobile：13581850130
E-mail: huahl(a)126.com
MSN: kvhua(a)msn.com
公司： 掌上维度（北京）科技有限公司
地址： 北京市西城区32号枫蓝国际中心B座504A
电话： 010－62220515