[Python-Dev] genexps slow?
jiwon
jiwon at softwise.co.kr
Wed Mar 31 02:41:43 EST 2004
> [Tim]
> > Make r a lot bigger, and I
> > expect
> > the genexp will get relatively faster (due to better cache behavior).
[Raymond ]
> Also, try a timing with "sum(x for x in xrange(100000))". This will
> highlight the differences in behavior. With xrange, this genexp will be
> able to execute entirely in cache.
I just tried timing it. For your information, here're results. :)
[jiwon at holmes] ./python ./Lib/timeit.py -s 'r=range(10000000)' 'sum(x for x
in r)'
10 loops, best of 3: 4.83 sec per loop
[jiwon at holmes] ./python ./Lib/timeit.py -s 'r=range(10000000)' 'sum([x for x
in r])'
10 loops, best of 3: 6.49 sec per loop
[jiwon at holmes] ./python ./Lib/timeit.py 'sum(x for x in xrange(10000000))'
10 loops, best of 3: 5.14 sec per loop
[jiwon at holmes] ./python ./Lib/timeit.py 'sum([x for x in
xrange(10000000)])'
10 loops, best of 3: 5.85 sec per loop
Tried with lazy-binding version of genexpr, and non-optimized version of
listcomp.
More information about the Python-Dev
mailing list