Skip to content

Instantly share code, notes, and snippets.

@stepheneb
Created November 29, 2009 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepheneb/244822 to your computer and use it in GitHub Desktop.
Save stepheneb/244822 to your computer and use it in GitHub Desktop.
Three simple pure Ruby benchmarks comparing Ruby 1.8.6, Ruby 1.9.2, JRuby 1.5.0dev, MacRuby 0.5, Rubinius 1.0.0-rc1 and MagLev Ruby 0.6 [1]
The benchmarks are run more than once because JRuby is running in server mode and optimizes the code while it is running.
Parse a 98k XML document and count one type of leaf element (466 entries) 100 times [2]
$ jruby --server --fast xml_benchmark_rexml.rb
rexml 8.658000 0.000000 8.658000 ( 8.658000)
rexml 4.940000 0.000000 4.940000 ( 4.940000)
$ jruby --server xml_benchmark_rexml.rb
user system total real
rexml 10.168000 0.000000 10.168000 ( 10.168000)
rexml 6.205000 0.000000 6.205000 ( 6.205000)
$ ruby xml_benchmark_rexml.rb
user system total real
rexml 8.990000 0.540000 9.530000 ( 9.609303)
rexml 8.900000 0.540000 9.440000 ( 9.555908)
$ ruby19 xml_benchmark_rexml.rb
user system total real
rexml 9.980000 0.180000 10.160000 ( 10.294687)
rexml 10.250000 0.170000 10.420000 ( 10.658629)
$ maglev-ruby xml_benchmark_rexml.rb
user system total real
rexml 13.210000 0.510000 13.720000 ( 16.434433)
rexml 13.260000 0.390000 13.650000 ( 16.645472)
$ bin/rbx xml_benchmark_rexml.rb
user system total real
rexml 44.513807 0.000000 44.513807 ( 44.513791)
rexml 41.221796 0.000000 41.221796 ( 41.221803)
$ macruby xml_benchmark_rexml.rb
user system total real
rexml 90.910000 3.240000 94.150000 ( 53.791530)
rexml 92.760000 3.110000 95.870000 ( 52.334891)
The same xml benchmark comparing different XML processing libraries in Ruby 1.8.6 and JRuby [4]
MRI 1.8.6
$ ruby xml_benchmarks.rb
Rehearsal --------------------------------------------
rexml 9.120000 0.560000 9.680000 ( 9.929643)
hpricot 0.640000 0.000000 0.640000 ( 0.682722)
libxml 0.350000 0.040000 0.390000 ( 0.408387)
nokogiri 0.510000 0.020000 0.530000 ( 0.541282)
---------------------------------- total: 11.240000sec
user system total real
rexml 9.130000 0.570000 9.700000 ( 10.018919)
hpricot 0.640000 0.010000 0.650000 ( 0.672481)
libxml 0.340000 0.010000 0.350000 ( 0.352505)
nokogiri 0.420000 0.020000 0.440000 ( 0.466002)
JRuby 1.5.0dev
$ jruby --server xml_benchmarks.rb
Rehearsal ---------------------------------------------------------
rexml 9.720000 0.000000 9.720000 ( 9.720000)
hpricot 1.781000 0.000000 1.781000 ( 1.782000)
jdom_document_builder 1.396000 0.000000 1.396000 ( 1.397000)
----------------------------------------------- total: 12.897000sec
user system total real
rexml 6.392000 0.000000 6.392000 ( 6.392000)
hpricot 0.922000 0.000000 0.922000 ( 0.922000)
jdom_document_builder 0.348000 0.000000 0.348000 ( 0.348000)
Running a Takeuchi function 5 times [3]
$ macruby tak.rb 2
user system total real
0.330000 0.010000 0.340000 ( 0.359792)
0.330000 0.000000 0.330000 ( 0.329469)
$ maglev-ruby tak.rb 2
user system total real
0.540000 0.010000 0.550000 ( 0.556373)
0.530000 0.000000 0.530000 ( 0.534777)
$ jruby --server --fast tak.rb 2
user system total real
1.921000 0.000000 1.921000 ( 1.871000)
1.002000 0.000000 1.002000 ( 1.002000)
$ bin/rbx tak.rb 2
user system total real
1.985358 0.000000 1.985358 ( 1.985415)
2.012621 0.000000 2.012621 ( 2.012675)
$ jruby --server tak.rb 2
user system total real
3.251000 0.000000 3.251000 ( 3.212000)
2.378000 0.000000 2.378000 ( 2.378000)
$ ruby19 tak.rb 2
user system total real
3.280000 0.020000 3.300000 ( 3.349039)
3.290000 0.020000 3.310000 ( 3.393350)
$ ruby tak.rb 2
user system total real
14.310000 0.100000 14.410000 ( 14.611532)
14.300000 0.120000 14.420000 ( 14.630269)
Running Hongli Lai's Ruby mergesort benchmark [5], adapted to run 2 times and to display the Java version when running in JRuby
$ jruby --server --fast mergesort_benchmarks/mergesort_bench.rb
Ruby version: JRuby 1.8.7 (2009-11-24 rev 174) [i386-jruby1.5.0.dev], platform: Java, version 1.6.0_15
user system total real
mergesort 2.152000 0.000000 2.152000 ( 2.152000)
mergesort 1.590000 0.000000 1.590000 ( 1.591000)
$ jruby --server mergesort_benchmarks/mergesort_bench.rb
Ruby version: JRuby 1.8.7 (2009-11-24 rev 174) [i386-jruby1.5.0.dev], platform: Java, version 1.6.0_15
user system total real
mergesort 2.727000 0.000000 2.727000 ( 2.728000)
mergesort 2.096000 0.000000 2.096000 ( 2.096000)
$ rbx mergesort_benchmarks/mergesort_bench.rb
Ruby version: MRI 1.8.7 (2009-11-25 rev 174), platform: i686-apple-darwin9.8.0
user system total real
mergesort 2.878490 0.000000 2.878490 ( 2.878506)
mergesort 2.221507 0.000000 2.221507 ( 2.221494)
$ maglev-ruby mergesort_benchmarks/mergesort_bench.rb
Ruby version: MRI 1.8.6 (2009-11-20 rev 114), platform: x86_64-darwin
user system total real
mergesort 2.290000 0.010000 2.300000 ( 2.335180)
mergesort 2.400000 0.020000 2.420000 ( 2.427145)
$ macruby mergesort_benchmarks/mergesort_bench.rb
Ruby version: MRI 1.9.0 (2008-06-03 rev 0), platform: universal-darwin9.0
user system total real
mergesort 5.610000 0.180000 5.790000 ( 3.921019)
mergesort 5.560000 0.190000 5.750000 ( 3.837314)
$ ruby19 mergesort_benchmarks/mergesort_bench.rb
Ruby version: MRI 1.9.2 (2009-11-24 rev -1), platform: i386-darwin9.8.0
user system total real
mergesort 4.050000 0.020000 4.070000 ( 4.081330)
mergesort 4.080000 0.030000 4.110000 ( 4.124799)
$ ruby mergesort_benchmarks/mergesort_bench.rb
Ruby version: MRI 1.8.6 (2008-08-11 rev 287), platform: universal-darwin9.0
user system total real
mergesort 9.380000 0.060000 9.440000 ( 9.516282)
mergesort 9.390000 0.060000 9.450000 ( 9.527420)
--------
[1] Tested versions of Ruby
JRuby 1.8.7 (2009-11-24 rev 174) [i386-jruby1.5.0.dev], platform: Java, version 1.6.0_15
MRI 1.9.2 (2009-11-24 rev -1), platform: i386-darwin9.8.0
MRI 1.8.6 (2008-08-11 rev 287), platform: universal-darwin9.0
MacRuby 0.5, MRI 1.9.0 (2008-06-03 rev 0), platform: universal-darwin9.0
Ruby version: MRI 1.8.6 (2009-12-03 rev 114), platform: x86_64-darwin
MagLev 0.6 (ruby 1.8.6) (2009-12-03 rev 22619-1073)
rubinius 1.0.0-rc1 (1.8.7 0f83f82c 2009-11-25 JI) [i686-apple-darwin9.8.0]
[2]: xml_benchmark_rexml.rb and associated xml data file here
http://svn.concord.org/svn/projects/trunk/common/ruby/xml_benchmarks/
[3] tak.rb, tak(24, 16, 8): see: http://gist.github.com/243272
[4] xml_benchmarks.rb, hpricot 0.8.2, nokogiri 1.4.0, libxml 1.1.3, jdom (custom in benchmark)
[5] Hongli Lai's Ruby mergesort benchmark
See: http://izumi.plan99.net/blog/index.php/2008/01/17/ruby-vs-php-performance/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment