Optimizing multiple dispatch

Jeff Epler jepler at unpythonic.net
Thu Jun 3 17:30:40 CEST 2004

Pyrex is just a translator, there's no dependency on a Pyrex library or
include file when you actually want to compile the generated .c

On Thu, Jun 03, 2004 at 04:55:19PM +0200, Jacek Generowicz wrote:
> Jeff Epler <jepler at unpythonic.net> writes:
> > Avoding map() may help:
> >     tuple([type(a) for a in args])
> Nonononononooooo!  :-)
> > ... hmm, map is faster than listcomp.  my mistake!
> :-)
> I've asked for optimization advice a few times here, and usually the
> responses include "replace map with a list comprehension" ... and yet
> the map is always faster. I wonder where people get this idea that map
> is slow ... until this started happening I had always assumed that
> "everyone" knows that the map/reduce/filter family are the fastest
> Python looping constructs.

No message about optimization should be without one downright wrong

The common wisdom about listcomp speed may apply when the body doesn't
include a function call, but the map version would include a lambda:
    $ timeit 'map(lambda x:x+1, range(100))'
    1000 loops, best of 3: 230 usec per loop
    $ timeit '[x+1 for x in range(100)]'
    10000 loops, best of 3: 156 usec per loop

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040603/17ea931c/attachment.pgp>

More information about the Python-list mailing list