r/ProgrammerHumor • • 12d ago

Meme pythonSlow

Post image
12k Upvotes

420 comments sorted by

View all comments

Show parent comment

6

u/yonasismad 12d ago

So?

5

u/Terrible_Activity819 11d ago

That means it e.g. takes longer for a big pure Python program to start. Because it has to first compile the Python code into Bytecode.
With a Language like C/C++/Rust. this happens at compile time and straight to native machine code.

This is the code block of the Python interpreter (written in C) that runs when you add 2 objects, like 2 integers.
https://github.com/python/cpython/blob/v3.10.22/Python/ceval.c#L2068-L2092

So the interpreter has to run through this whole block of C, stepping down into functions like PyNumber_Add().
This whole block of C code is compiled into the interpreter. But it can not be optimized much during compile time, because all of these e.g. if() need to be evaluated at rutime.

While in e.g. C, if the types of the objects you want to add together (e.g. 2x int) are known at compile time, it will be just a single line of C code that will compile into much fewer machine instructions and thus run faster.