| Even with compute performance it is probably closer than you expect. Python isn't evaluated line-by-line, even in micropython, which is about the only common implementation that doesn't work in the same way. Cython VM will produce an AST of opcodes, and binary operations just end up popping off a stack, or you can hit like pypy. How efficiently you can keep the pipeline fed is more critical than computation costs. int a = 5;
int b = 10;
int sum = a + b;
Is compiled to: MOV EAX, 5
MOV EBX, 10
ADD EAX, EBX
MOV [sum_variable]
In the PVM binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.That pop, pop isn't much more expensive on modern CPUs and some C compilers will use a stack depending on many factors. And even in C you have to use structs of arrays etc... depending on the use case. Stalled pipelines and fetching due to the costs is the huge difference. It is the setup costs, GC, GIL etc... that makes python slower in many cases. While I am not suggesting it is as slow as python, Java is also byte code, and often it's assumptions and design decisions are even better or at least nearly equal to C in the general case unless you highly optimize. But the actual equivalent computations are almost identical, optimizations that the compilers make differ. |