[prev in list] [next in list] [prev in thread] [next in thread]
List: python-bugs-list
Subject: [issue39801] list.insert is slow due to manual memmove
From: Stefan Pochmann <report () bugs ! python ! org>
Date: 2020-02-29 16:11:28
Message-ID: 1582992688.24.0.071544861703.issue39801 () roundup ! psfhosted ! org
[Download RAW message or body]
New submission from Stefan Pochmann <stefan.pochmann@gmail.com>:
Using a list's insert function is much slower than using slice assignment:
> python -m timeit -n 100000 -s "a=[]" "a.insert(0,0)"
100000 loops, best of 5: 19.2 usec per loop
> python -m timeit -n 100000 -s "a=[]" "a[0:0]=[0]"
100000 loops, best of 5: 6.78 usec per loop
(Note that the list starts empty but grows to 100,000 elements.)
At first I thought maybe it's the attribute lookup or function call overhead or so, \
but inserting near the end shows that that's negligible:
> python -m timeit -n 100000 -s "a=[]" "a.insert(-1,0)"
100000 loops, best of 5: 79.1 nsec per loop
I asked at StackOverflow and someone pointed out that list.insert uses a manual loop \
instead of memmove: https://stackoverflow.com/a/60466572/12671057
----------
components: Interpreter Core
messages: 362986
nosy: Stefan Pochmann
priority: normal
severity: normal
status: open
title: list.insert is slow due to manual memmove
type: performance
versions: Python 3.8
_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue39801>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/python-bugs-list%40marc.info
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic