C语言中:
int fib(int n){ if (n
Python中:
def fib(n): if n
下面是它们各自的执行时间:
$ time ./fib 3.099s $ time python fib.py 16.655s
首先我们来安装一个python模块:psyco,安装非常简单,只需要执行如下命令:
sudo apt-get install python-psyco
或者你是在centos的话,执行:
sudo yum install python-psyco
然后我们来验证一下:
#引入psyco模块,author: www.pythontab.com import psyco psyco.full() def fib(n): if n
哈哈,见证奇迹的时刻!!
$ time python fib.py 3.190s
现在我几乎大部分python代码都会加上如下代码,享受psyco所带来的速度提升
try: import psyco psyco.full() except ImportError: pass # psyco not installed so continue as usual
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did86789