Re: Good Use of GOTO
- Posted by Jeremy Cowgar <jeremy at ?owgar.?om> Jun 06, 2008
- 809 views
Ok, here are the benchmarks you asked for CK... [jeremy@jdesk 40goto]$ time exu ffunc.e real 0m2.424s user 0m2.420s sys 0m0.003s [jeremy@jdesk 40goto]$ time exu fgoto.e real 0m1.142s user 0m1.143s sys 0m0.000s The code is: ffunc.e (factorial function)
function factorial(atom a) if a < 2 then return a end if return a*factorial(a-1) end function object ign for i = 1 to 1000000 do ign = factorial(20) end for
and fgoto.e (factorial goto)
function factorial(atom a) atom b b = a label "start" if a <= 2 then goto "end" end if a = a - 1 b = b * a goto "start" label "end" return b end function object ign for i = 1 to 1000000 do ign = factorial(20) end for
Now, bear in mind, this is an optimization. The non-goto version of factorial is much simpler, but also much slower. You would only resort to a situation like this if you have measured speed and speed was not acceptable for your situation. Goto has been committed as a branch (not part of trunk everyone!) you can download it, compile and run these benchmarks for yourself. The SVN repo is: http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria -- Jeremy Cowgar http://jeremy.cowgar.com