[issue38436] Improved performance for list addition.
Brandt Bucher
report at bugs.python.org
Fri Oct 11 14:20:35 EDT 2019
Brandt Bucher <brandtbucher at gmail.com> added the comment:
Thanks, Pablo, for providing that. So the changes look like mostly a wash on these benchmarks.
Serhiy:
I do not see any significant change in + operator timing on my machine (again, just a rough test):
$ ./python.exe -m timeit -s z=0 z+0 # master
10000000 loops, best of 5: 21.3 nsec per loop
$ ./python.exe -m timeit -s z=0 z+0 # list-add
10000000 loops, best of 5: 21.2 nsec per loop
I'm aware that unpacking is "better". With that said, adding a list literal (or a slice of any list, or a list comprehension) to another list is a fairly common operation (I count several dozen examples in the stdlib). Even though these cases only have two operands, they will still see the speed-up.
And the speed-up is good, even in these cases. You can compare using the new code:
$ ./python.exe -m timeit -s l=[0,1,2,3] [0,1,2,3]+l # Hits new branch
5000000 loops, best of 5: 87.9 nsec per loop
$ ./python.exe -m timeit -s l=[0,1,2,3] l+[0,1,2,3] # Hits old branch
5000000 loops, best of 5: 92.5 nsec per loop
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38436>
_______________________________________
More information about the Python-bugs-list
mailing list