This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Stefan Pochmann
Recipients Stefan Pochmann
Date 2020-02-29.16:11:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582992688.24.0.071544861703.issue39801@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-02-29 16:11:28Stefan Pochmannsetrecipients: + Stefan Pochmann
2020-02-29 16:11:28Stefan Pochmannsetmessageid: <1582992688.24.0.071544861703.issue39801@roundup.psfhosted.org>
2020-02-29 16:11:28Stefan Pochmannlinkissue39801 messages
2020-02-29 16:11:27Stefan Pochmanncreate