Python interpreter speed

Tim Roberts timr at probo.com
Tue Apr 21 01:21:54 EDT 2009


Ryniek90 <ryniek90 at gmail.com> wrote:
>
>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?

Remember that NONE of your comments (or mine) are inherently required parts
of either Java or Python.  We are merely talking about the most popular
implementations.

Java is compiled to an intermediate language, which is then re-compiled at
execution time to machine code.

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.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list