[Numpy-discussion] "import numpy" is slow
Wed Jul 30 15:51:45 CDT 2008
On Wed, Jul 30, 2008 at 4:12 PM, Andrew Dalke <email@example.com> wrote:
> 4) numpy.testing takes 0.041 seconds to import. The text I quoted
> above says that it's a numpy requirement that 'testing' always be
> imported, even though I'm hard pressed to figure out why that's
I suppose it's necessary for providing the test() and bench()
functions in subpackages, but I that isn't a good reason to impose
upon all users the time required to set up numpy.testing.
> Assuming it is important, 0.020 seconds is spent
> importing 'difflib'
> difflib: 0.020 (utils)
> heapq: 0.016 (difflib)
> itertools: 0.003 (heapq)
> operator: 0.003 (heapq)
> bisect: 0.005 (heapq)
> _bisect: 0.003 (bisect)
> _heapq: 0.003 (heapq)
> which is only used in numpy.testing.utils:assert_string . That can
> be deferred.
> numpytest: 0.012 (numpy.testing)
> glob: 0.005 (numpytest)
> fnmatch: 0.002 (glob)
> shlex: 0.006 (numpytest)
> collections: 0.003 (shlex)
> numpy.testing.utils: 0.000 (numpytest)
> but notice that 'glob' while imported is never used in 'numpytest',
> and that 'shlex' can easily be a deferred import. This saves (for
> the common case) 0.01 seconds.
Thanks for taking the time to find those; I just removed the unused
glob and delayed the import of shlex, difflib, and inspect in
More information about the Numpy-discussion