Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Python list vs tuple vs set: Read/Write Speed Benchmark

DEV Community·TildAlice·22 days ago
#W1F4MwjK
Reading 0:00
15s threshold

list vs tuple vs set: What I Found After 100K Iterations I ran 100,000 read/write operations on Python's three core collection types. tuple beat list by 12% in lookups. set crushed both by 99.8% for membership checks. But here's what caught me off guard: list writes were slower than tuple creation for batches under 1000 items. Most Python guides tell you "tuples are faster because they're immutable." That's... partially true. The real story involves hash tables, memory allocation strategies, and one gotcha with in operators that I wish I'd known three years ago. Let me show you the actual numbers. Photo by Christina Morillo on Pexels The Benchmark Setup I tested on Python 3.11.7 (the version where dictionary ordering became a language guarantee, not just CPython quirk). MacBook M1 Pro, 16GB RAM. Each operation repeated 100K times using timeit with 3-second warmup.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More