[Python-Dev] genexps slow? (original) (raw)

Raymond Hettinger python at rcn.com
Wed Mar 31 00:48:53 EST 2004


Can anybody explain this?

[guido at guido linux]$ ./python ../Lib/timeit.py -s 'r=range(10000)' 'sum([x for x in r])' 100 loops, best of 3: 7.75 msec per loop [guido at guido linux]$ ./python ../Lib/timeit.py -s 'r=range(10000)' 'sum(x for x in r)' 100 loops, best of 3: 8.23 msec per loop

I optimized list comps so that they run much faster than they did back when Alex first made the comparative timings. On my machine, they run twice as fast.

Comparing listcomps to genexps, there are several factors affecting the relative timings:

Raymond



More information about the Python-Dev mailing list