Re: Speed of Python

2007-09-11 Thread Dick Moores
At 09:42 AM 9/7/2007, wang frank wrote: >Are there any way to speed it up? How about psyco? Dick Moores XP, Python 2.5.1, editor is Ulipad -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed of Python

2007-09-07 Thread Marc 'BlackJack' Rintsch
On Fri, 07 Sep 2007 23:53:48 +, wang frank wrote: >>From: "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> >>To: python-list@python.org >>Subject: Re: Speed of Python >>Date: 7 Sep 2007 23:17:55 GMT >> >>On Fri, 07 Sep 2007 22:5

Re: Speed of Python

2007-09-07 Thread Carl Banks
On Sep 7, 12:42 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Hi, > > While comparing the speed of octave and matlab, I decided to do a similar > test for python and matlab. The result shows that python is slower than > matlab by a factor of 5. It is not bad since octave is about 30 time slower > t

Re: Speed of Python

2007-09-07 Thread Terry Reedy
"wang frank" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |z=log(j); This matlab code is faster in part than your Python equivalent: | > > z=math.log(m) because of the repeated lookup of log in the math module. So, replace | > > import math with

Re: Speed of Python

2007-09-07 Thread wang frank
I am just trying to compare the speed with matlab. The arrange is used for another test, that is why it shows up in the mail. Thanks Frank From: "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> To: python-list@python.org Subject: Re: Speed of Python Date: 7 Sep 200

Re: Speed of Python

2007-09-07 Thread Marc 'BlackJack' Rintsch
On Fri, 07 Sep 2007 22:59:26 +, wang frank wrote: > I also have tried to use numpy to speed it up. However, surprisingly, it is > slower than the pure python code. > > Here is the code: > import numpy > arange=numpy.arange > nlog=numpy.log > def bench6(n): > for i in xrange(n): >

Re: Speed of Python

2007-09-07 Thread wang frank
From: "Kurt Smith" <[EMAIL PROTECTED]> To: "wang frank" <[EMAIL PROTECTED]> Subject: Re: Speed of Python Date: Fri, 7 Sep 2007 16:49:05 -0500 On 9/7/07, wang frank <[EMAIL PROTECTED]> wrote: > Hi, > Here is the matlab code: > function

Re: Speed of Python

2007-09-07 Thread wang frank
ajaksu <[EMAIL PROTECTED]> To: python-list@python.org Subject: Re: Speed of Python Date: Fri, 07 Sep 2007 19:27:45 - On Sep 7, 2:37 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > I am not familiar with python, so I just simply try to reproduce the same > code in p

Re: Speed of Python

2007-09-07 Thread ajaksu
On Sep 7, 2:37 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > I am not familiar with python, so I just simply try to reproduce the same > code in python. Seems almost correct, but from what I guess of MatLab, George's suggestions make it a bit more fair. > If you think that my python script is not

Re: Speed of Python

2007-09-07 Thread Istvan Albert
On Sep 7, 12:42 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Is my conclusion correct that Python is slower than matlab? There are ways to speed up code execution, but to see substantial improvement you'll need to use numpy and rework the code to operate on vectors/matrices rather than building

Re: Speed of Python

2007-09-07 Thread George Sakkis
On Sep 7, 12:42 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Is my conclusion correct that Python is slower than matlab? Are there any > way to speed it up? Yes, use Numpy for any non trivial number-crunching task: http://numpy.scipy.org/. Even if you don't, you can speed up the original functi

Re: Speed of Python

2007-09-07 Thread Roberto Bonvallet
On Sep 7, 1:37 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Hi, > Here is the matlab code: > function [z]=bench1(n) > for i=1:n, > for j=1:1000, > z=log(j); > z1=log(j+1); > z2=log(j+2); > z3=log(j+3); > z4=log(j+4); > z5=log(j+5); > z6=l

Re: Speed of Python

2007-09-07 Thread wang frank
ct: Re: Speed of Python Date: Fri, 07 Sep 2007 17:19:02 - On Sep 7, 12:42 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Here is the bench1.py: > import math > def bench1(n): > for i in range(n): > for j in range(1000): >

Re: Speed of Python

2007-09-07 Thread Roberto Bonvallet
On Sep 7, 12:42 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Here is the bench1.py: > import math > def bench1(n): > for i in range(n): > for j in range(1000): > m=j+1 > z=math.log(m) > z1=math.log(m+1)

Re: Speed of Python

2007-09-07 Thread S bastien Boisg rault
On Sep 7, 6:42 pm, "wang frank" <[EMAIL PROTECTED]> wrote: Matlab (aka MATrix LABoratory) has been designed with numeric computations in mind (every object being natively a n-dim array). If you wish to develop that kind of applications in Python, consider using the numerical array structure provi

Re: speed of python vs matlab.

2006-12-14 Thread greg
Chao wrote: > I did some search, in previous discussion, people has compared > python/numpy vs matlab, > but it is actually comparison between numpy(which is implemented in c) > vs matlab. Yes, matlab is operating on whole arrays at a time, like numpy. So it's not surprising that they have compar

Re: speed of python vs matlab.

2006-12-14 Thread Robert Kern
Chao wrote: > While trying this another question comes up, > psyco seems to be able to optimize built-in functions & user's code, if > I call a function from an external library, it seems doesn't help. > A simple thing is I placed a = numpy.sin(a) in the loop rather than a = > a+1, in this case, >

Re: speed of python vs matlab.

2006-12-14 Thread Chao
Thank you guys for your interest, I tried two things 1) put code into a function 2) use psyco. 1) by putting them into a function, there is a significant improvement, around 30% the running time will be around 0.3sec 2) by using psyco, it really does a great job, the running time is around 0.045

Re: speed of python vs matlab.

2006-12-14 Thread bearophileHUGS
Chao, you can also try Psyco, applied on functions, and when necessary using its metaclass too. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: speed of python vs matlab.

2006-12-14 Thread Roberto Bonvallet
Chao wrote: > My Bad, the time used by python is 0.46~0.49 sec, > I tried xrange, but it doesn't make things better. Actually it does: it doesn't waste time and space to create a big list. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list

Re: speed of python vs matlab.

2006-12-14 Thread Christophe
Chao a écrit : > My Bad, the time used by python is 0.46~0.49 sec, > I tried xrange, but it doesn't make things better. > > import time > tic = time.time() > a = 1.0 > > array = range(1000) > > for i in array: > for j in array: > a = a + 0.1 > > toc = time.time() > print toc-tic,' ha

Re: speed of python vs matlab.

2006-12-13 Thread Jonathan Curran
On Wednesday 13 December 2006 18: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 fini

Re: speed of python vs matlab.

2006-12-13 Thread Chao
My Bad, the time used by python is 0.46~0.49 sec, I tried xrange, but it doesn't make things better. import time tic = time.time() a = 1.0 array = range(1000) for i in array: for j in array: a = a + 0.1 toc = time.time() print toc-tic,' has elapsed' used by matlab is 0.012sec tic

Re: speed of python vs matlab.

2006-12-13 Thread Andrew Sackville-West
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 second

Re: speed of python vs matlab.

2006-12-13 Thread Gabriel Genellina
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.

Re: speed of python vs matlab.

2006-12-13 Thread Aidan Steele
On 13 Dec 2006 16:07:20 -0800, Chao <[EMAIL PROTECTED]> 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(