Speed: Ruby vs. Groovy
I'd like to set the record straight on an issue I've seen mentioned on the Internet. I've seen the Ruby fan-boys parading about (again) claiming that Ruby is faster than Groovy, and therefore RoR is better than Grails.
I've written a simple suite of benchmarks pitting many languages against each other (even the venerable Fortran). These tests show something which applies directly to this issue - when using Groovy with dynamic type, Ruby does, indeed, outperform Groovy ... marginally. That said, Groovy has this fabulous feature where (if you want to - meaning more choice for a programmer) you can use static typing. Groovy can also be compiled to Java bytecode (I do realise that Ruby 2 is going to have this, but it's not there yet, so it's a moot point at this stage). Both of these optional features throw Groovy into turbo. Simply static typing in a few places immediately makes Groovy faster than Ruby (including faster than JRuby), and compiling increases that performance gain.
So, if we're going to look at this purely from a language potential stand-point, then no one can honestly make the claim that Ruby is faster than Groovy - a simple, easy-to-implement switch-over to static typing negates this argument.
UPDATE
To prove the point, I've used a simple factorial calculation to illustrate the fallacy of thinking the Groovy language itself is slower than Ruby (not comparing Grails to Ruby on Rails). The test consisted of performing a factorial on 20, repeated 10,000,000 times to get a measurable result. After a little tinkering, it became obvious that recursion was not the faster option, so I used simple looping.
C Ruby: 197,777ms
Groovy (with dynamic typing): 46,721ms
So, in actual fact, during at least mathematic functions, Groovy far outpaces Ruby. As an interesting point of comparison, Java scored 32ms. What does this have to do with anything? Well, it does mean that as a Groovy developer, you can very easily fall back on Java for any process which requires better speeds. Ruby as a language does not offer this (JRuby may offer it, but this is not a standard feature of the language itself, only tje JRuby implementation). You may opt for developing a native gem for Ruby, but let's face it, that is going to be a great deal more difficult than what Groovy can do with Java.
Comments
There are no comments for this post.
Add comment
Visit my Friends and Family
If you've enjoyed my site, please take a moment to visit my friends and family, many of whom have some interesting insights, and entertaining thoughts and ideas.
- Crause Family - the family website
- Peter Crause - my father
- Justin Crause - my brother
- Cencina Photomagic - great photographer