vendredi 1 janvier 2010
Quick note on python vs jython performance
Par Sébastien Pierre, vendredi 1 janvier 2010 à 11:13 :: Langages
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:
- On CPython, Pamela processed 60 KB/s, and the test run for 30.27s
- On Jython 2.5r0, Pamela processed 30.25 kb/s, and the test run for 63.03s
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:
- On CPython, Retro serves 426.52 req/s
- On Jython, Retro serves 53.79 req/s (and if you set concurrency to
-C100you'll likely get a connection reset by peer...)
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 !