[Python-3000] Python 3000 Status Update (Long!)

Neil Toronto ntoronto at cs.byu.edu
Fri Jun 22 21:32:42 CEST 2007


Alex Martelli wrote:
> $ python -mtimeit -s'import itertools as it' -s'L=range(-7,17)' 'for x
> in it.imap(abs,L): pass'
> 100000 loops, best of 3: 3 usec per loop
> $ python -mtimeit -s'import itertools as it' -s'L=range(-7,17)' 'for x
> in (abs(y) for y in L): pass'
> 100000 loops, best of 3: 4.47 usec per loop
>
> (imap is faster in this case because the built-in name 'abs' is looked
> up only once -- in the genexp, it's looked up each time, sigh --
> possibly the biggest "we should REALLY tweak the language to let this
> be optimized sensibly" gotcha in Python, IMHO).
>   

What is it about the language as it stands that requires abs() to be 
looked up each iteration?

Neil



More information about the Python-3000 mailing list