This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients casevh, josh.r, lemburg, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, vstinner, yselivanov, zbyrne
Date 2016-02-03.18:50:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <56B24BD6.2080600@egenix.com>
In-reply-to <CAMpsgwaARXgeGZbZ_BwB0tiSt38f6ewaG43WNPr+Jzups-FKYQ@mail.gmail.com>
Content
On 03.02.2016 18:05, STINNER Victor wrote:
> 
>> python -m timeit  "sum([x * x * 1 for x in range(100)])"
> 
> If you only want to benchmark x*y, x+y and list-comprehension, you
> should use a tuple for the iterator.

... and precalculate that in the setup:

python -m timeit -s "loops=tuple(range(100))" "sum([x * x * 1 for x in loops])"

# python -m timeit "sum([x * x * 1 for x in range(100)])"
100000 loops, best of 3: 5.74 usec per loop
# python -m timeit -s "loops=tuple(range(100))" "sum([x * x * 1 for x in loops])"
100000 loops, best of 3: 5.56 usec per loop

(python = Python 2.7)
History
Date User Action Args
2016-02-03 18:50:03lemburgsetrecipients: + lemburg, rhettinger, mark.dickinson, pitrou, vstinner, casevh, serhiy.storchaka, yselivanov, josh.r, zbyrne
2016-02-03 18:50:03lemburglinkissue21955 messages
2016-02-03 18:50:03lemburgcreate