maandag 22 juni 2009

A round-up of Groovy performance comparisons

There has been much written about groovy performance. Here is a round-up of the results of a quick google search I did. Obviously, all of these tests are centered around micro-benchmarks, which might not be representative for real code you might write, but the results are very consistent.

http://www.fischerlaender.net/perl/poor-groovy-performance

This is a test summing values read from a file. Groovy is about 10x slower than Java, all other languages tested are very close together.

http://www.christianschenk.org/blog/performance-comparison-between-groovy-and-java/

A couple of very small benchmarks that are not in any way representative for real code. Groovy performs about 1000x worse than Java in all tests. Strangly enough, the author still concludes that you can use Groovy to create 'beans' without incurring a performance penalty ("... who wants to create so many objects in the first place?").

http://pegolon.wordpress.com/2008/01/24/quick-ruby-groovy-performance-comparison/

A very simple comparison of Groovy with Ruby using a very simple loop with an assignment or addition. Groovy performs 4x to 8x worse than Ruby.

http://tiago.org/cc/2008/03/21/groovy-performance-speed/
http://tiago.org/cc/2008/03/23/revisiting-groovy-performance-issues/

A pair of blogs in which a program reads a textfile, comparing columns. The Java version takes 4 seconds; the Groovy version initially takes 4 minutes, but this is later improved (through a number of optimizations) to about 1 minute and 30 seconds. The first (slower) version is a more or less direct translation of the Java program, the later (faster) verision is considered more 'Groovy-esque' by commenters.

http://www.jroller.com/rants/entry/why_is_groovy_so_slow

A number of tests, both trivial in nature as well as pretty 'lifelike'. Groovy is much slower than Java, by factors 7.6, 33, 37, and 56, respectively. The author expresses disappointment in this:
Well, this is really disappointing. I expected Groovy to be slower but not by that much. In order to understand where does such a performance hit come from we have to peek under the hood. The culprit of all this is of course Groovy's dynamic nature, implemented as MOP. MOP is a way for Groovy to know which class elements (fields/properties, methods, interfaces, superclasses, etc..) are defined on an object and to have a way to alter that data or invoke it.
And finally:
http://www.javalobby.org/java/forums/t101157.html

The table with results in this article looks like this:
ray.java 12.89s
ray.scala 11.224s
ray.groovy 2h 31m 42s

Groovy is a lot slower.

Groovy 1.6

Most of the tests I refer to above have been done with Groovy version 1.5.6. Meanwhile, a beta version of Groovy 1.6 has arrived, which promises performance improvements -- up to a factor 4.5, if the website can be believed. It would be interresting to re-run all the above tests with this newer version. If time allows, I might do this.

Conclusions

Groovy appears to have some catching up to do in the performance realm. Things like the Meta Object model and its using wrapper objects instead of primitives do have their performance penalties. Perhaps with a focus on performance (as appears to be the case with the new 1.6 version), Groovy can start catching up to Java and other languages, either on the JVM or not. In the mean time, if performance is really important, I think I will stick with Java for now.