python与matlab的速度。 [英] speed of python vs matlab.

查看:476
本文介绍了python与matlab的速度。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试用python开发一些数字代码,但是

很失望。


一个非常简单的测试,


a = 1.0

for i in range(1000):

for j in range(1000):
不幸的是,
a = a + 1


完成需要4.5秒(我的机器很好.P4

3.0G,1G RAM,它根据机器配置的不同而不同,但是应该在同一级别上b / b
for matlab,同样的操作需要0.1秒,


我使用numpy& scipy,他们大多数时候都解决了这个问题,但是有些情况下你无法通过向量来避免循环。我非常感谢python的优点,但我想我必须在这些

数字代码中放弃它。(图像处理算法),用于应用程序

dev / scripting,它仍然是我的第一选择。


一个好消息是相同的代码需要9.8秒的红宝石。

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.

推荐答案

在星期三13/12/2006 21:07,Chao写道:
At Wednesday 13/12/2006 21:07, Chao wrote:

>我一直在尝试使用python开发一些数字代码,但是很失望。

一个非常简单的测试,

a = 1.0

我在范围内(1000):

为j范围内(1000):

a = a + 1

不幸的是,它需要4.5秒才能完成(我的机器很好.P4
3.0G,1G RAM,根据机器配置而有所不同,但应该处于同一水平)
>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)



你如何衡量它? 4.5秒是太多了。无论如何,尝试使用

xrange而不是范围。这是做时间的标准方法:


---剪切---

def测试():

a = 1.0
$ x $ b for x in xrange(1000):
$ x $ b for j in xrange(1000):

a = a + 1


if __name __ ==''__ main__'':

来自timeit import Timer

t = Timer(" test()","来自__main__ import test")

print t.repeat(repeat = 3,number = 1)

--- cut ---


我的硬件少了大约0.24秒。


对于面向矢量的操作,NumArray软件包很适合。

-

Gabriel Genellina

Softlab SRL

__________________________________________________

Correo Yahoo!

Espacio para todos tus mensajes,antivirus y antispam?gratis!

?Abrítucuenta ya! - http://correo.yahoo.com.ar


2006年12月13日星期三下午04:07:20 -0800,Chao写道:
On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote:

我一直在尝试用python开发一些数字代码但是

很失望。


一个非常简单的测试,


a = 1.0


for i in range(1000):

for j in range(1000):

a = a + 1 <不幸的是,
完成需要4.5秒(我的机器很好.P4

3.0G,1G RAM,它根据机器配置而有所不同,但应该

属于同一水平)
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)



有些东西不在那里。


andrew @ debian: 〜

somethings not right there.

andrew@debian:~


cat pytimetest.py

a = 1.0

for i in range(1000):

对于范围内的j(1000):

a = a + 1

andrew @ debian:〜
cat pytimetest.py
a=1.0
for i in range (1000):
for j in range (1000):
a=a+1
andrew@debian:~


这篇关于python与matlab的速度。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆