Speed of Python
George Sakkis
george.sakkis at gmail.com
Fri Sep 7 20:49:56 CEST 2007
On Sep 7, 12:42 pm, "wang frank" <f... at hotmail.co.jp> 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 function by ~25% if
you replace range() with xrange() and bind the log function to a local
variable:
def bench2(n):
from math import log
for i in xrange(n):
for j in xrange(1000):
m=j+1
z=log(m)
z1=log(m+1)
z2=log(m+2)
z3=log(m+3)
z4=log(m+4)
z5=log(m+5)
z6=log(m+6)
z7=log(m+7)
z8=log(m+8)
z9=log(m+9)
return z9
HTH,
George
More information about the Python-list
mailing list