5 ms·
Why is it slower compared to a normal list?
by lang4d 2y ago
Why is it slower compared to a normal list?
- sgarland 2y agoThe simplistic answer is that lists have been heavily optimized over the years, arrays haven’t been touched much. I’m not positive on why lists are faster to create than lists, though. Retrieval makes sense (lists already store the Python object, arrays have to cast it back), but creation I’m unsure about. I’ll check dis.dis. EDIT: from a sibling comment above [0], maybe because array reallocs are done much more granularly than lists, so as it grows, it’ll have to do so more frequently compared to lists? [0]: https://github.com/python/cpython/blob/main/Modules/arraymodule.c#L162 https://github.com/python/cpython/blob/main/Modules/arraymod...