New submission from Sergey Fedoseev <fedoseev.ser...@gmail.com>:
Script for benchmarks: NAME=list-slice.json python -m perf timeit --name "l[len(l):] = reversed(l)" -l 1 -s "l = [None] * 1000000" "l[len(l):] = reversed(l)" --append $NAME python -m perf timeit --name "l[len(l):] = l" -l 1 -s "l = [None] * 1000000" "l[len(l):] = l" --append $NAME python -m perf timeit --name "l[::-1] = l" -s "l = [None] * 1000000" "l[::-1] = l" --append $NAME python -m perf timeit --name "l[:] = l" -s "l = [None] * 1000000" "l[:] = l" --append $NAME python -m perf timeit --name "l[len(l)//2:] = l" -l 1 -s "l = [None] * 1000000" "l[len(l)//2:] = l" --append $NAME python -m perf timeit --name "l[:len(l)//2] = l" -l 1 -s "l = [None] * 1000000" "l[:len(l)//2] = l" --append $NAME python -m perf timeit --name "l[len(l)//4:len(l)*3//4] = l" -l 1 -s "l = [None] * 1000000" "l[len(l)//4:len(l)*3//4] = l" --append $NAME Results table: +------------------------------+-------------------+------------------------------------+ | Benchmark | list-slice-master | list-slice | +==============================+===================+====================================+ | l[len(l):] = reversed(l) | 8.44 ms | 5.18 ms: 1.63x faster (-39%) | +------------------------------+-------------------+------------------------------------+ | l[len(l):] = l | 7.88 ms | 3.37 ms: 2.34x faster (-57%) | +------------------------------+-------------------+------------------------------------+ | l[::-1] = l | 10.4 ms | 582 us: 17.85x faster (-94%) | +------------------------------+-------------------+------------------------------------+ | l[:] = l | 10.6 ms | 86.1 ns: 123128.46x faster (-100%) | +------------------------------+-------------------+------------------------------------+ | l[len(l)//2:] = l | 11.1 ms | 2.08 ms: 5.33x faster (-81%) | +------------------------------+-------------------+------------------------------------+ | l[:len(l)//2] = l | 11.5 ms | 1.76 ms: 6.53x faster (-85%) | +------------------------------+-------------------+------------------------------------+ | l[len(l)//4:len(l)*3//4] = l | 11.3 ms | 2.27 ms: 4.98x faster (-80%) | +------------------------------+-------------------+------------------------------------+ ---------- components: Interpreter Core messages: 321908 nosy: sir-sigurd priority: normal severity: normal status: open title: performance of some list slice assignment can be improved type: performance _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34152> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com