Well its been long time and I’ve been sitting quite in a corner waiting for this loud fight between the two Rubies to end. I once had a debate with one of ruby pro (when 1.9.1 was newly out) that JRuby can always stay ahead in speed (There are a-lot details available on how it does that for example this one). I had to start a project recently and choose a platform; ruby was obvious choice, after doing first few iterations when it came to select a database I realised Java has much better support for NoSQL stores than ruby (I can see people getting offended here; but accept it and live with it!) which lead me to the same old discussion in my mind which one is faster? I poked around on Google and found some mixed results. So I made up my mind and decided to do benchmarks myself! Here are the rules of game:
I will give each ruby complete isolation (ruby 1.9.2 and jruby 1.6.3 both latest stables) and 3 runs on same code just before starting off I will take the system time in milliseconds and at the end print out the total time elapsed. Since I don’t care about the start up time consumed I am pretty carelessly selecting jruby optimising “server” mode (perfect for web application scenario). My machine is a normal laptop with Intel Dual Core , 3GB RAM, and a pretty normal HDD.
Time to bust the bubble!
Run 1 focuses on calculation intensive thing; for that I took one of codes from Internet of generating random numbers you can view source code.
Ruby Runtime:
JRuby Runtime:
Ok fine (it was close) may be Java’s JIT or something else made.
So, Run 2 focuses on class instantiation and dynamic module extension, you can view source code here.
Ruby Runtime:
JRuby Runtime:
I am stopping right here for now; I mean why can’t a native language code beat a same code on top of JVM? It’s pretty obvious, I have to make some more benchmarks before I make a decision and put the nail in the coffin; So until I do that you people to enjoy this, give me your feedback and may be start thinking about porting your code to JRuby if its worth it!
To be continued…
Design by Simon Fletcher. Powered by Tumblr.
© Copyright 2010