map, LC, genexp

Bryan belred1 at yahoo.com
Sat Nov 13 22:12:37 EST 2004


i thought that LC and genexp were supposed to be faster than map.  i also thought i read somewhere in this group that 
the slowest looping mechanism in 2.4 is 20% faster than the fastest looping mechanism in 2.3.  if i'm wrong about this, 
remembered wrong or did something wrong, please let me know.  here are some timeit tests i did on my machine.  notice 
that map is faster in both python versions and that LC24/LC23 is only a 5.5% speed improvement.

python 2.3

timeit "for i in map(str, xrange(100)): pass"
10000 loops, best of 3: 118 usec per loop

timeit "for i in [str(x) for x in xrange(100)]: pass"
1000 loops, best of 3: 200 usec per loop

python 2.4b1

timeit "for i in map(str, xrange(100)): pass"
10000 loops, best of 3: 144 usec per loop

timeit "for i in [str(x) for x in xrange(100)]: pass"
10000 loops, best of 3: 189 usec per loop

timeit "for i in (str(x) for x in xrange(100)): pass"
10000 loops, best of 3: 185 usec per loop


thanks,

bryan



More information about the Python-list mailing list