Created
October 14, 2012 15:01
-
-
Save alh13/3888844 to your computer and use it in GitHub Desktop.
Enable TC-Optimization in Ruby
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
# https://speakerdeck.com/u/jeg2/p/10-things-you-didnt-know-ruby-could-do | |
RubyVM::InstructionSequence.compile_option = { :tailcall_optimization => true, | |
:trace_instruction => false } | |
eval <<end | |
def factorial(n, result = 1) | |
if n == 1 | |
result | |
else | |
factorial(n - 1, n * result) | |
end | |
end | |
end | |
p factorial(30_000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment