Skip to content

Instantly share code, notes, and snippets.

@adaedra
Created August 20, 2012 13:21
Show Gist options
  • Save adaedra/3403964 to your computer and use it in GitHub Desktop.
Save adaedra/3403964 to your computer and use it in GitHub Desktop.
Ruby vs JRuby
(pegasus) % cat benchmark.rb
#!/usr/bin/env ruby
t_b = Time.now.to_f
# 50'000 * sin [ -90 .. 90 ]
50000.times do
( -90 .. 90 ).each do |x|
Math.sin(x)
end
end
t_e = Time.now.to_f
puts "Time : #{t_e - t_b}"
(pegasus) % ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
(pegasus) % time ruby benchmark.rb
Time : 4.937260150909424
ruby benchmark.rb 4,94s user 0,01s system 99% cpu 4,959 total
(pegasus) % rvm use jruby
Using /Users/adaedra/.rvm/gems/jruby-1.6.7.2
(pegasus) % ruby -v
jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java]
(pegasus) % time ruby benchmark.rb
Time : 1.27999997138977
ruby benchmark.rb 2,58s user 0,12s system 136% cpu 1,983 total
(pegasus) %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment