Speed of Python
Terry Reedy
tjreedy at udel.edu
Sat Sep 8 02:45:15 CEST 2007
"wang frank" <fw3 at hotmail.co.jp> wrote in message
news:BAY122-F37CD62BB3682998CD2C45AB4C50 at phx.gbl...
| 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
from math import log
Also make that the top line of the function so 'log' is a local variable.
Then delete 'math.' everywhere.
That said, such artificial benchmarks do not strike me as terribly useful.
More useful, for instance, for appropriate applications, might be doing a
fourier transform on a 2**20 length vector with both matlab and numpy/scipy
tjr
More information about the Python-list
mailing list