Lesson: performance will never be what you expect. Therefore, always measure, never believe.
Some reasons why you can see these numbers (and from the first sentence, some of them may be completely wrong):
C compiled for the "i586" processor (also called Pentium). This processor was sold from 1993 to 2000. Have you seen him recently? I think no. Thus, the C code is not really optimized for what your processor can do (or, conversely, in a different way: today processors are trying very hard to be a fast Pentium processor). Java, OTOH, compiled for your processor when loading code. It can pull out some tricks that C simply cannot. The price is that program C starts at 15 ms, and Java program starts at 4 seconds.
Python does not have JIT (only at compiler time). All code is converted to bytecode, which is then interpreted. This means that the loop above turns into a dozen bytecode instructions, which are then interpreted by C. This takes time. Python is not intended for huge loops, it is for smart algorithms that you simply cannot express in any other language (at least not with the same amount of code and readability).
Thus, just as it makes no sense to go shopping with an 18 t truck (you can transport everything, but you wonβt find a parking place), choose your programming language according to the problem you need to solve. Should it be small and fast? C. Just fast? Java. Flexible? Python Flexible & Fast: Python with a helper library in C (e.g. NumPy).
source share