◐ Shell
clean mode source ↗

Message 242238 - Python tracker

I got a report that summing numbers is noticably slower on Python 3. This is easily reproducible:


$ time python2.7 -c "print sum(xrange(3, 10**9, 3)) + sum(xrange(5, 10**9, 5)) - sum(xrange(15, 10**9, 15))"
233333333166666668

real    0m6.165s
user    0m6.100s
sys     0m0.032s


$ time python3.4 -c "print(sum(range(3, 10**9, 3)) + sum(range(5, 10**9, 5)) - sum(range(15, 10**9, 15)))"
233333333166666668

real    0m16.413s
user    0m16.086s
sys     0m0.089s


I can't tell from initial poking what's the core issue here. Both examples produce equivalent bytecode, the builtin_sum() function is only noticably different in the fact that it uses PyLong_* across the board, including PyLong_AsLongAndOverlow. We'll need to profile this, which I didn't have time for yet.