Top
Best
New

Posted by WoodenChair 1/1/2026

Python numbers every programmer should know(mkennedy.codes)
429 points | 186 commentspage 4
esafak 1/1/2026|
The point of the original list was that the numbers were simple enough to memorize: https://gist.github.com/jboner/2841832

Nobody is going to remember any of the numbers on this new list.

mikeckennedy 1/1/2026|
That's a fair point @esafak. I updated the article with something akin to the doubling chart of numbers in the original article from 2012.
dr_kretyn 1/1/2026||
Initially I thought how efficient strings are... but then I understood how inefficient arithmetic is. Interesting comparison but exact speed and IO depend on a lot of things, and unlikely one uses Mac mini in production so these numbers definitely aren't representative.
gcanyon 1/1/2026||
As someone who most often works in a language that is literally orders of magnitude slower than this —- and has done so since CPU speeds were measured in double-digit megahertz —- I am crying at the notion that anything here is measured in nanoseconds
mwkaufma 1/1/2026||
Why? If those micro benchmarks mattered in your domain, you wouldn't be using python.
coldtea 1/1/2026||
That's an "all or nothing" fallacy. Just because you use Python and are OK with some slowdown, doesn't mean you're OK with each and every slowdown when you can do better.

To use a trivial example, using a set instead of a list to check membership is a very basic replacement, and can dramatically improve your running time in Python. Just because you use Python doesn't mean anything goes regarding performance.

mwkaufma 1/1/2026||
That's an example of an algorithmic improvement (log n vs n), not a micro benchmark, Mr. Fallacy.
coldtea 1/1/2026||
"Mr. Fallacy."? Got any better juvenile name-calling?

The case is among the example numbers given in TFA:

"Dict lookup by key", "List membership check"

Does it have to spell out the difference is algorithmic in this case for the comparison to be useful?

Or, inversely, is the difference between e.g. memory and disk access times insignificant, because it's not algorithmic?

PhilipRoman 1/1/2026||
...and other hilarious jokes you can tell yourself!
superlopuh 1/2/2026||
I'm surprised that the `isinstance()` comparison is with `type() == type` and not `type() is type`, which I would expect to be faster, since the `==` implementation tends to have an `isinstance` call anyway.
superlopuh 1/2/2026|
Also seems like the repo is now private, so I can't open an issue, or reproduce the numbers.
nodja 1/1/2026||
I think a lot of commenters here are missing the point.

Looking at performance numbers is important regardless if it's python, assembly or HDL. If you don't understand why your code is slow you can always look at how many cycles things take and learn to understand how code works at a deeper level, as you mature as a programmer things will become obvious, but going through the learning process and having references like these will help you to get there sooner, seeing the performance numbers and asking why some things take much longer—or sometimes why they take the exact same time—is the perfect opportunity to learn.

Early in my python career I had a python script that found duplicate files across my disks, the first iteration of the script was extremely slow, optimizing the script went through several iterations as I learned how to optimize at various levels. None of them required me to use C. I just used caching, learned to enumerate all files on disk fast, and used sets instead of lists. The end result was that doing subsequent runs made my script run in 10 seconds instead of 15 minutes. Maybe implementing in C would make it run in 1 second, but if I had just assumed my script was slow because of python then I would've spent hours doing it in C only to go from 15 minutes to 14 minutes and 51 seconds.

There's an argument to be made that it would be useful to see C numbers next to the python ones, but for the same reason people don't just tell you to just use an FPGA instead of using C, it's also rude to say python is the wrong tool when often it isn't.

woodruffw 1/1/2026||
Great reference overall, but some of these will diverge in practice: 141 bytes for a 100 char string won’t hold for non-ASCII strings for example, and will change if/when the object header overhead changes.
JBits 1/1/2026||
One of the reasons I'm really excited about JAX is that I hope it will allow me to write fast Python code without worrying about these details.
lunixbochs 1/1/2026||
I'm confused why they repeatedly call a slots class larger than a regular dict class, but don't count the size of the dict
Retr0id 1/1/2026|
> Numbers are surprisingly large in Python

Makes me wonder if the cpython devs have ever considered v8-like NaN-boxing or pointer stuffing.

More comments...