[Python-Dev] Py2.6 ideas
Michele Simionato
michele.simionato at gmail.com
Wed Feb 21 09:33:00 CET 2007
Michele Simionato <michele.simionato <at> gmail.com> writes:
> Finally I did some timing of code like this::
>
> from itertools import imap
> Point = namedtuple('Point x y'.split())
>
> lst = [(i, i*i) for i in range(500)]
>
> def with_imap():
> for _ in imap(Point, lst):
> pass
>
> def with_star():
> for _ in (Point(*t) for t in lst):
> pass
>
> and as expected the performances are worse with the * notation
BTW, I take back this point. It is true that the generation expression
is slower, but the direct equivalent of imap is starmap and using
that I don't see a significant difference in execution times. So it seems that
starmap is smart enough to avoid unnecessary tuple unpacking (as you
probably know ;-). I still don't like for a subclass to have an incompatible
signature with the parent class, but that's just me.
Michele Simionato
More information about the Python-Dev
mailing list