Skip to content

Instantly share code, notes, and snippets.

@dnagir
Created January 9, 2012 05:19
Show Gist options
  • Save dnagir/1581274 to your computer and use it in GitHub Desktop.
Save dnagir/1581274 to your computer and use it in GitHub Desktop.
JRuby & MRI call vs send
#!/bin/sh
source ~/.bash_profile
echo "======================== JRUBY ========================="
rvm use jruby &&
ruby -v &&
TIMES=100_000 ruby test.rb
TIMES=1000_000 ruby test.rb
TIMES=100_000_000 ruby test.rb
echo "======================== MRI ========================="
rvm use jruby &&
rvm use 1.9.3 &&
ruby -v &&
TIMES=100_000 ruby test.rb
TIMES=1000_000 ruby test.rb
TIMES=100_000_000 ruby test.rb
> sh run.sh
======================== JRUBY =========================
Using /Users/dnagir/.rvm/gems/jruby-1.6.5.1
jruby 1.6.5.1 (ruby-1.9.2-p136) (2011-12-27 1bf37c2) (Java HotSpot(TM) Client VM 1.6.0_29) [darwin-i386-java]
Benchmark for 100000 iterations
user system total real
send 0.068000 0.000000 0.068000 ( 0.069000)
call 0.017000 0.000000 0.017000 ( 0.017000)
Benchmark for 1000000 iterations
user system total real
send 0.460000 0.000000 0.460000 ( 0.460000)
call 0.145000 0.000000 0.145000 ( 0.145000)
Benchmark for 100000000 iterations
user system total real
send 43.735000 0.000000 43.735000 ( 43.735000)
call 14.309000 0.000000 14.309000 ( 14.309000)
======================== MRI =========================
Using /Users/dnagir/.rvm/gems/jruby-1.6.5.1
Using /Users/dnagir/.rvm/gems/ruby-1.9.3-p0
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
Benchmark for 100000 iterations
user system total real
send 0.040000 0.000000 0.040000 ( 0.044717)
call 0.020000 0.000000 0.020000 ( 0.021673)
Benchmark for 1000000 iterations
user system total real
send 0.430000 0.000000 0.430000 ( 0.439424)
call 0.220000 0.000000 0.220000 ( 0.221586)
Benchmark for 100000000 iterations
user system total real
send 46.150000 0.010000 46.160000 ( 46.163589)
call 23.390000 0.000000 23.390000 ( 23.387312)
require 'benchmark'
class Sample
def hello
end
end
max = ENV['TIMES'].to_i
puts "Benchmark for #{max} iterations"
Benchmark.bm do |x|
x.report("send") { max.times {|n| Sample.new.send("hello") } }
x.report("call") { max.times {|n| Sample.new.hello } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment