Python interpreter speed

R

Ryniek90

Hi.

Standard Python interpreter's implementation is written in C language. C
code while compilation, is compilled into machine code (the fastest
code). Python code is compiled into into byte-code which is also some
sort of fast machine code. So why Python interpreter is slower than Java
VM? Being written in C and compilled into machine code, it should be as
fast as C/Asm code.
What's wrong with that?

Greets and thank you.
 
S

Stefan Behnel

Tim said:
The Python you're thinking of (CPython) is compiled to an intermediate
language, which is then interpreted by an interpreter loop, somewhat
remeniscent of Forth. It takes more cycles per instruction to run that
interpreter loop than it does to run the machine language, but not by much.
Java is not that much faster than CPython.

There is another implementation (Jython) which compiled Python to the Java
intermediate language, which can then be JIT compiled, exactly like Java.

There is also IronPython, which is Python for the .NET framework. It
compiles to a different intermediate language, which is also compiled at
execution time to machine code.

Not to forget PyPy, which uses an optimising JIT to compile things to
native code.

There's also Cython, where the intermediate language is (optimised) C, and
the compilation to machine code happens at build time (or JIT-like at
import time if you use pyximport).

Regarding this:
Java is not that much faster than CPython.

That is a rather simplified statement. To be a tiny bit more accurate, Java
is faster for some applications and slower for others.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,832
Latest member
UtaHetrick

Latest Threads

Top