Java 20xfaster then Python !!??

Stuart D. Gathman stuart at bmsi.com
Fri Jan 10 12:34:15 EST 2003


On Fri, 10 Jan 2003 05:13:06 -0500, Axel Kowald wrote:

> I just had a look at these very detailed benchmark tests,
> http://www.bagley.org/~doug/shootout/, and I was surprised to see that
> often java is 20 times faster than python !!
> 
> How can this be? Both languages interprete bytecode. Maybe because java
> has a JIT compiler ??
> Is there any hope that python might become faster in future releases ?

I am a big fan of Java and Jython, but your conslusion is misleading.
First of all, the 20x is for a JITed Java VM.  This does indeed attain C
like speed once it gets going.  The cost is long startup (while the code
is custom compiled) and huge memory consumption.

If you run Java in interpreted mode (classic VM), it has low memory
consumption comparable to python - but is only slightly faster (due to
being less dynamic).

The Python technology corresponding to Java JIT is Psyco.  It is
available now and has similar advantages/drawbacks to Java JIT.  (It uses
a lot of memory and Psyco compiled code is often faster than C.)

The Minimal Python Project is a new project to replace most of CPython
with a Psyco compiled Python core - with the expected result of being
faster than C.  IBM has a similar open source project for Java - the VM
and JIT are all written in Java.  (It used to be called Jalapeno, but was
renamed when it was open sourced.)

The reason dynamically compiled code can be faster than statically
compiled C code is that it is optimized for the exact runtime
environment.  For instance, in Java, if a method has not been overridden,
calls to it are compiled as final or even inlined.  If the method is
eventually overridden, affected compiled code is discarded (and
recompiled differently if used again).  Psyco goes even further and
compiles multiple versions of a function, each optimized for different
calling environments.

Summary,
  If you want results similar to Java JITs in Python today (high speed
and high memory consumption), then use Psyco.

-- 
	      Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.




More information about the Python-list mailing list