DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

list.append vs Comprehension vs deque: 100k Benchmark

The 2.1x Speed Gap No One Talks About

Most Python tutorials tell you list comprehensions are faster than append() loops. They're right, but they miss the real story: collections.deque can beat both by over 2x for certain insertion patterns, and the performance gap widens as you scale past 10k elements.

I benchmarked three common ways to build a 100,000-element list: manual append(), list comprehension, and deque with conversion. The results expose a fundamental misunderstanding about how Python allocates memory for growing lists. If you've ever built a parser, event buffer, or streaming data handler that progressively accumulates elements, you've probably left performance on the table.

Detailed image of computer source code displayed on a screen, showcasing web development elements.

Photo by Markus Spiske on Pexels

The Three Contenders

Here's the setup. Python 3.11, timeit with 100 runs, Intel i7-9700K (your mileage will vary on M1/M2 chips — Apple Silicon's memory subsystem behaves differently).


python
import timeit
from collections import deque

# Method 1: Classic append loop
def build_with_append(n):
    result = []

---

*Continue reading the full article on [TildAlice](https://tildalice.io/list-append-vs-comprehension-vs-deque-benchmark/)*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)