A friend of mine is working on a project where his Python app has to work on Jython (Python on the JVM). As he had the bad surprise of seeing a noticable performance decrease, I wanted to check this for myself.

I know the JVM is not very good for dynamic languages (yet), but I wanted to test this with a real application. So I took a collection of Pamela files from a real project I finished a couple of months ago, and made Pamela parse the whole files 100 times (Pamela is a markup to HTML processor, similar to HAML).

The numbers are not very suprising, and a bit disappointing for the JVM as a runtime for dynamic languages:

The tests do not take into account the VM startup, and all the data is pre-loaded to memory. If you compare this very simple benchmark to results of Ruby vs JRuby it seems like having a 50% performance hit is not so bad when switching from native to JVM runtime.

I did another comparison, which is to start a simple Retro web service and run Apache Benchmark (ab -n1000) on it. The result are not really better:

My bet is that if you use the JDK library (java.util.collections, java.io, etc) you'll likely get better performance -- but the utility of Jython seems to be either running existing Python libraries on the JVM or using Python as a "glueing language" for your native JVM objects. In this latter case, you might as well look into other scripting languages available for the JVM like JavaScript or Lisp !

Anyway, things are likely to change when dynamic method dispatch gets implemented in Java 7 !