python和matlab计算速度对比_python与matlab的速度。
I''ve been trying to develop some numerical codes with python, howevergot disappointed.A very simple test,a = 1.0for i in range(1000):for j in range(1000):a = a+1unfortunately, it took 4.5 seconds to

I''ve been trying to develop some numerical codes with python, however
got disappointed.
A very simple test,
a = 1.0
for i in range(1000):
for j in range(1000):
a = a+1
unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)
for matlab, the same operation took 0.1 seconds,
I use numpy & scipy, they solve the problem most of the times, but
there are cases you can''t avoid loops by vectors. I appreciate the
elegancy of python so much, but I guess I have to gave it up in these
numerical codes.(image processing algorithms), for application
dev/scripting, it''s still my first choice.
A good news is that the same code takes ruby 9.8 seconds.
解决方案At Wednesday 13/12/2006 21:07, Chao wrote:
>I''ve been trying to develop some numerical codes with python, however
got disappointed.
A very simple test,
a = 1.0
for i in range(1000):
for j in range(1000):
a = a+1
unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)
How do you measure it? 4.5 secs is far too much. Anyway, try using
xrange instead of range. This is the standard way to do timings:
--- cut ---
def test():
a = 1.0
for i in xrange(1000):
for j in xrange(1000):
a = a+1
if __name__==''__main__'':
from timeit import Timer
t = Timer("test()", "from __main__ import test")
print t.repeat(repeat=3,number=1)
--- cut ---
I got about 0.24 secs with far less hardware.
For vector-oriented operations the NumArray package is well suited.
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis!
?Abrí tu cuenta ya! - http://correo.yahoo.com.ar
On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote:
I''ve been trying to develop some numerical codes with python, however
got disappointed.
A very simple test,
a = 1.0
for i in range(1000):
for j in range(1000):
a = a+1
unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)
somethings not right there.
andrew@debian:~
cat pytimetest.py
a=1.0
for i in range (1000):
for j in range (1000):
a=a+1
andrew@debian:~
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)