New submission from Sergey Fedoseev <fedoseev.ser...@gmail.com>:
list_slice() is used by PyList_GetSlice(), list_subscript() and for list copying. In list_subscript() slice indices are already normalized with PySlice_AdjustIndices(), so slice normalization currently performed in list_slice() is only needed for PyList_GetSlice(). Moving this normalization from list_slice() to PyList_GetSlice() provides minor speed-up for list copying and slicing: $ python -m perf timeit -s "copy = [].copy" "copy()" --duplicate=1000 --compare-to=../cpython-master/venv/bin/python /home/sergey/tmp/cpython-master/venv/bin/python: ..................... 26.5 ns +- 0.5 ns /home/sergey/tmp/cpython-dev/venv/bin/python: ..................... 25.7 ns +- 0.5 ns Mean +- std dev: [/home/sergey/tmp/cpython-master/venv/bin/python] 26.5 ns +- 0.5 ns -> [/home/sergey/tmp/cpython-dev/venv/bin/python] 25.7 ns +- 0.5 ns: 1.03x faster (-3%) $ python -m perf timeit -s "l = [1]" "l[:]" --duplicate=1000 --compare-to=../cpython-master/venv/bin/python /home/sergey/tmp/cpython-master/venv/bin/python: ..................... 71.5 ns +- 1.4 ns /home/sergey/tmp/cpython-dev/venv/bin/python: ..................... 70.2 ns +- 0.9 ns Mean +- std dev: [/home/sergey/tmp/cpython-master/venv/bin/python] 71.5 ns +- 1.4 ns -> [/home/sergey/tmp/cpython-dev/venv/bin/python] 70.2 ns +- 0.9 ns: 1.02x faster (-2%) ---------- messages: 336184 nosy: sir-sigurd priority: normal severity: normal status: open title: move index normalization from list_slice() to PyList_GetSlice() type: performance versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36062> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com