Running ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-darwin10.0.0] on an older white macbook:
def f
@i += 1
f
end
@i = 0
begin
f
rescue SystemStackError
puts @i
end
outputs 9353 for me, meaning Ruby craps out with fewer than 10,000 calls on the stack.
With cross-recursion, such as:
def f
@i += 1
g
end
def g
f
end
it craps out in half the time, at 4677 (~= 9353 / 2).
I can squeeze out a few more iterations by wrapping the recursive call in a proc:
def f
@i += 1
yield
end
@i = 0
@block = lambda { f(&@block) }
begin
f(&@block)
rescue SystemStackError
puts @i
end
which gets up to 4850 before erroring out.