Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Last active August 29, 2015 14:13
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 yorickpeterse/898682b0a8290ded03d7 to your computer and use it in GitHub Desktop.
Save yorickpeterse/898682b0a8290ded03d7 to your computer and use it in GitHub Desktop.
Manually running the Rubinius JIT on a totally legit fib() benchmark.
require 'benchmark/ips'
class Bench
def fact(n)
if n > 1
n * fact(n-1)
else
1
end
end
end
b = Bench.new
Benchmark.ips do |bench|
bench.report 'fact(2000)' do
b.fact(2000)
end
end
require 'benchmark/ips'
class Bench
def fact(n)
if n > 1
n * fact(n-1)
else
1
end
end
end
b = Bench.new
Rubinius::JIT.compile(b, b.method(:fact).executable)
Benchmark.ips do |bench|
bench.report 'fact(2000)' do
b.fact(2000)
end
end
$ ruby /tmp/bench.rb
Calculating -------------------------------------
fact(2000) 38.000 i/100ms
-------------------------------------------------
fact(2000) 801.057 (±15.0%) i/s - 3.876k
$ ruby /tmp/bench_jit.rb
Calculating -------------------------------------
fact(2000) 76.000 i/100ms
-------------------------------------------------
fact(2000) 811.939 (± 3.8%) i/s - 4.104k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment