[Numpy-discussion] "import numpy" is slow
Andrew Dalke
dalke at dalkescientific.com
Tue Aug 5 11:51:25 EDT 2008
I just added ticket 874
http://scipy.org/scipy/numpy/ticket/874
which on my machine takes the import time from 0.15 seconds down to
0.093 seconds.
A bit over a month ago it was about 0.33 seconds. :)
The biggest trick I didn't apply was to defer importing the re
module, and only compile the patterns when they are needed. That
would save about 0.013 seconds, but the result would be rather
fragile as people rarely consider deferring pattern definitions.
I'll submit a patch for it, expected it to be rejected. ;)
I noticed that two places import the standard Python math library,
which doesn't seem necessary:
numpy/lib/__init__.py:
import math
__all__ = ['emath','math']
'math' is never used in that module. It does mean that 'numpy.math'
is the same as Python's math module, which I didn't expect. I didn't
understand why it was explicitly in the __all_ list so I didn't
change it. All tests pass without it.
numpy/lib/index_tricks.py:
import math
..
size.append(math.ceil((key[k].stop - start)/
(step*1.0)))
Wouldn't numpy.ceil be okay here? All tests pass when I use numpy.ceil.
This would save about 0.002 seconds, so it's a small improvement.
I think there's a subtle and minor bug in _datasource.
def __del__(self):
# Remove temp directories
if self._istmpdest:
rmtree(self._destpath)
Is 'rmtree' guaranteed to be present in the module scope if the
object is garbage collected during Python shutdown?
Andrew
dalke at dalkescientific.com
More information about the NumPy-Discussion
mailing list