Skip to content

Instantly share code, notes, and snippets.

@vitaly-pushkar
Last active August 29, 2015 13:57
Show Gist options
  • Save vitaly-pushkar/9640656 to your computer and use it in GitHub Desktop.
Save vitaly-pushkar/9640656 to your computer and use it in GitHub Desktop.
require 'benchmark'
def fibonacci(n)
def fib(current, nxt, n)
return current if n == 0
fib(nxt, current + nxt, n - 1)
end
fib(0, 1, n)
end
puts Benchmark.measure { fibonacci 5000 }
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false }
eval <<end
def fibonacci(n)
def fib(current, nxt, n)
return current if n == 0
fib(nxt, current + nxt, n - 1)
end
fib(0, 1, n)
end
end
puts Benchmark.measure { fibonacci 5000 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment