[issue32534] Speed-up list.insert

STINNER Victor report at bugs.python.org
Tue Jan 16 04:30:58 EST 2018


STINNER Victor <victor.stinner at gmail.com> added the comment:

> jeethu at dev:cpython  (3.7_list_insert_memmove)$ ./python -m timeit -s "l = []" "for _ in range(100): l.insert(0, None)"

Please don't use timeit, but perf timeit to run such *microbenchmark* (time smaller than 1 ms).

Your benchmark measures also the performance of the loop, it might be significant in such short loop (100 items). You may try to unroll the loop manually, and truncate the list:

vstinner at apu$ python3 -c 'print("l.insert(None); " * 3 + "l.clear();")'
l.insert(None); l.insert(None); l.insert(None); l.clear();

Example:

python3 -m perf timeit -s 'l=[]' $(python3 -c 'print("l.insert(0, None); " * 100 + "l.clear();")') --duplicate 100


Jeethu Rao: Are you using CPU isolation? What is your OS?

----------
nosy: +vstinner

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32534>
_______________________________________


More information about the Python-bugs-list mailing list