Find limit of recursion: Difference between revisions

→‎{{header|Phix}}: added a saner test
(Added missing parameter type to compile with Nim 1.4. Changed comment to describe behavior with this version.)
(→‎{{header|Phix}}: added a saner test)
Line 2,165:
 
=={{header|Phix}}==
On a 32-bit version the limit is an impressive 3431 million. OfI coursehave onseen realthis wordhit apps43 withmillion moreon parameters64 etcbit, but it willthen be smaller. Unfortunately other problems are stopping me from testing this onforced a 64-bithard version right nowreboot.
<lang Phix>atom t1 = time()+1
 
Line 2,183:
 
recurse()</lang>
{{out|output|text=&nbsp; 32 bit}}
<pre>
C:\Program Files (x86)\Phix>p e01
Line 2,224:
C:\Program Files (x86)\Phix>
</pre>
=== saner ===
It takes about 25 seconds to build that stack and slightly longer to tear it down. You should also note that somewhat less clean error reports are likely: even the above could theoretically fail mid-sprintf and hence exercise a completely different error handling path, and there are likely to be several hundred different ways to fail when there is no more memory.
The following much more safely merely tests it can reach 20,000,000, plus however far it gets in the last whole-second
<lang Phix>atom t1 = time()+1
integer depth = 0, depth_blown = false
string btd = "building"
procedure recurse()
if time()>t1 then
printf(1,"depth: %d (%s)\n",{depth,btd})
if depth>20_000_000 then
depth_blown = true
btd = "tearing down"
end if
t1 = time()+1
end if
if depth_blown then
depth -= 1
else
depth += 1
recurse() -- (build)
recurse() -- (tear down)
end if
end procedure
recurse()</lang>
{{out}}
<pre>
depth: 8857573 (building)
depth: 17197111 (building)
depth: 25309477 (building)
depth: 20023696 (tearing down)
depth: 14825154 (tearing down)
depth: 9601027 (tearing down)
depth: 3725849 (tearing down)
</pre>
 
=={{header|PHP}}==
7,813

edits