More speed comparisons of Ruby 1.8, Ruby 1.9, JRuby, Rubinius and MacRuby using Graticule

Thursday, April 24, 2008

Here are some more benchmarks for a speed comparison between Ruby 1.8 (MRI), Ruby 1.9 (YARV), Rubinius and JRuby (brand new 1.1.1 release) and this time included in the package is also MacRuby 0.1 (r88 from the test branch to be precise) which I recently discovered (more on MacRuby soon in a seperate post ;) ). Also, this time is measured by the Benchmark lib and not from the time utility.

The benchmark is based on the Graticule library which apart from the geocoding it provides (including Google, Yahoo, etc...) it also has the ability to calculate distances with various methods. For this benchmark, I first got the cooordinates of the biggest European cities and saved them as Locations (Graticule's class) in a YAML file. Then (and this is where the benchmark begins) I loaded them from the YAML file and calculated each pairs' distance (=> all cities with all cities) using the default method that Graticule uses. Here is the code* :



require 'benchmark'
require 'yaml'
require File.dirname(__FILE__) + '/../../lib/graticule'

class DistanceCalculationBenchmarks
def self.european_cities(print_results = false)
Benchmark.bmbm do |x|
x.report("Largest european cities tour:") {
5.times do

locations = YAML.load_file('cities.yml')

costs = {}
locations.each_index do |loc|
costs[loc] = {}
end

locations.each_index do |loc_a|
locations.each_index do |loc_b|

if loc_a != loc_b and costs[loc_a][loc_b] == nil
d = locations[loc_a].distance_to(locations[loc_b])
costs[loc_a][loc_b] = costs[loc_b][loc_a] = d
end
end
end

end
}
end

end
end

DistanceCalculationBenchmarks.european_cities


and here are the results, first in raw text:



Running Distance Calcutions using Graticule for Europe's 100 Largest cities with five iterations & rehearsal.
Current time: Thu Apr 24 02:26:39 +0300 2008

Ruby 1.8...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 1.270000 0.010000 1.280000 ( 1.288320)
-------------------------------------------------------- total: 1.280000sec

user system total real
Largest european cities tour: 1.270000 0.010000 1.280000 ( 1.279469)
---------------------------------------------------------------------------

Ruby 1.9...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 1.270000 0.020000 1.290000 ( 1.289113)
-------------------------------------------------------- total: 1.290000sec

user system total real
Largest european cities tour: 1.280000 0.010000 1.290000 ( 1.284230)
---------------------------------------------------------------------------

Rubinius (bbe450f22) (04/15/2008)...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 46.258145 0.000000 46.258145 ( 46.258139)
------------------------------------------------------- total: 46.258145sec

user system total real
Largest european cities tour: 46.594087 0.000000 46.594087 ( 46.594102)
---------------------------------------------------------------------------

JRuby 1.1.1 with no flags...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 3.717000 0.000000 3.717000 ( 3.718000)
-------------------------------------------------------- total: 3.717000sec

user system total real
Largest european cities tour: 2.949000 0.000000 2.949000 ( 2.950000)
---------------------------------------------------------------------------

JRuby 1.1.1 and flags -J-server ...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 4.820000 0.000000 4.820000 ( 4.821000)
-------------------------------------------------------- total: 4.820000sec

user system total real
Largest european cities tour: 2.191000 0.000000 2.191000 ( 2.191000)
---------------------------------------------------------------------------

JRuby 1.1.1 and flags -X+C...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 3.701000 0.000000 3.701000 ( 3.701000)
-------------------------------------------------------- total: 3.701000sec

user system total real
Largest european cities tour: 3.030000 0.000000 3.030000 ( 3.030000)
---------------------------------------------------------------------------

JRuby 1.1.1 and flags -J-server -X+C...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 5.601000 0.000000 5.601000 ( 5.601000)
-------------------------------------------------------- total: 5.601000sec

user system total real
Largest european cities tour: 2.647000 0.000000 2.647000 ( 2.647000)
---------------------------------------------------------------------------

MacRuby 0.1...
Rehearsal -----------------------------------------------------------------
Largest european cities tour: 3.480000 0.340000 3.820000 ( 5.454403)
-------------------------------------------------------- total: 3.820000sec

user system total real
Largest european cities tour: 3.450000 0.330000 3.780000 ( 5.241581)
---------------------------------------------------------------------------



and in an obviously more elegant way :





Ok, the first thing I noticed is that once again Rubinius is not really usable for this particular piece of code (which was also the case with my precious benchmark) :( JRuby was also slower by 50% (on average) which means that I am either a bless or a curse for the Jruby team (it's the second time I give them "bad" results from a benchmark). Finally, the newcomer, aka MacRuby, is somewhere near (on average again) with JRuby. Not bad for a 0.1 release but it's not really that usable yet (my previous benchmark doesn't work yet - I created a nice ticket in their tracker... :D This bug seems to be fixed on trunk, gonna check it out later).



The specs of the machine and the misc versions are the same with what they were before except the updated Rubinius.



NOTE: After I ploted the chart I noticed that in the code I was using a hash for the costs and not an array. I re-run the benchmark with an array instead of a hash and even though it didn't make any serious difference in Ruby 1.8, 1.9, Rubinius and MacRuby JRuby was half or a second faster than before. In case anyone wants the new results let me know and I will try to update the post (text and graph). Otherwise I leave it as it is with this note :)



* : This may be the code for the benchmark but I also have a custom patched Graticule lib because Graticule requires the ActiveSupport gem which for the time being (and until 2.1 is released) it's incompatible with MacRuby. I think it was ok with the rest BUT it only uses 3-4 things from ActiveSupport and I prefer to copy them inside the Graticule and get rid of the "require 'active_support'" which makes the execution time increase about 10%. More on this also on a upcoming post.

So, that's it for the time being. Have fun...


,,,,,,,

1 comments:

  • 阿童木

    Audemars Pigeut Royal Oak series ladies watch after 40 years of precipitation, replica rolex Audemars Pigeut Royal Oak series "cream gold watch" to highlight the Audemars Pigeut adhere to continuous innovation, uk replica watches as well as the Jacqueline Dimier design of the classic replica watches uk table shall be. As one of the few modern ladies watch designer, design style Jacqueline Dimier for Audemars Pigeut lay still affects the design philosophy of Audemars Pigeut watches.

  • Post a Comment