[Numpy-discussion] "import numpy" performance

Andrew Dalke dalke@dalkescientific....
Mon Jul 2 18:16:40 CDT 2012

On Jul 3, 2012, at 12:46 AM, David Cournapeau wrote:
> It is indeed irrelevant to your end goal, but it does affect the
> interpretation of what import_array does, and thus of your benchmark


> Focusing on polynomial seems the only sensible action. Except for
> test, all the other stuff seem difficult to change without breaking
> anything.

I confirm that when I comment out numpy/__init__.py's "import polynomial"
then the import time for numpy.core.multiarray goes from

0.084u 0.031s 0:00.11 100.0%	0+0k 0+0io 0pf+0w


0.058u 0.028s 0:00.08 87.5%	0+0k 0+0io 0pf+0w

numpy/polynomial imports:
from polynomial import Polynomial
from chebyshev import Chebyshev
from legendre import Legendre
from hermite import Hermite
from hermite_e import HermiteE
from laguerre import Laguerre

and there's no easy way to make these be lazy imports.

Strange! The bottom of hermite.py has:

exec polytemplate.substitute(name='Hermite', nick='herm', domain='[-1,1]')

as well as similar code in laguerre.py, chebyshev.py, hermite_e.py,
and polynomial.py.

I bet there's a lot of overhead generating and exec'ing
those for each import!


More information about the NumPy-Discussion mailing list