Message259500
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) |
|
Date |
User |
Action |
Args |
2016-02-03 18:50:03 | lemburg | set | recipients:
+ lemburg, rhettinger, mark.dickinson, pitrou, vstinner, casevh, serhiy.storchaka, yselivanov, josh.r, zbyrne |
2016-02-03 18:50:03 | lemburg | link | issue21955 messages |
2016-02-03 18:50:03 | lemburg | create | |
|