Last active
August 29, 2015 14:13
-
-
Save yorickpeterse/898682b0a8290ded03d7 to your computer and use it in GitHub Desktop.
Manually running the Rubinius JIT on a totally legit fib() benchmark.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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