Proposal: Inline Import

Alex Martelli aleax at mail.comcast.net
Sat Dec 10 21:11:21 EST 2005


Erik Max Francis <max at alcyone.com> wrote:

> Shane Hathaway wrote:
> 
> > Let me fully elaborate the heresy I'm suggesting: I am talking about
> > inline imports on every other line of code.  The obvious implementation
> > would drop performance by a double digit percentage.
> 
> Module importing is already idempotent.  If you try to import an 
> already-imported module, inline or not, the second (or subsequent) 
> imports are no-operations.

Hmmm, yes, but they're rather SLOW no-operations...:

Helen:~ alex$ python -mtimeit -s'import sys' 'import sys'
100000 loops, best of 3: 3.52 usec per loop

Now this is just a humble ultralight laptop, to be sure, but still, to
put the number in perspective...:

Helen:~ alex$ python -mtimeit -s'import sys' 'sys=23'    
10000000 loops, best of 3: 0.119 usec per loop

...we ARE talking about a factor of 30 or so slower than elementary
assignments (I'm wondering whether this may depend on import hooks, or,
what else...).


Alex



More information about the Python-list mailing list