New submission from Łukasz Langa:

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.

----------
components: Interpreter Core
messages: 242238
nosy: lukasz.langa, pitrou, rhettinger
priority: normal
severity: normal
stage: needs patch
status: open
title: sum() several times slower on Python 3
type: performance
versions: Python 3.4, Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24076>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to