Re: Good Use of GOTO
- Posted by Chris Bensler <eu at creat?veportal.c?> Jun 06, 2008
- 828 views
c.k.lester wrote: > > Jeremy Cowgar wrote: > > c.k.lester wrote: > > > How does this compare: > > > function factorial_fast(atom a) > > > end function > > > I show similar improvement vs factorial() without the use of GOTO. > > > > > > > I ran it a few times. > > So, my factorial_fast() runs in about 1.57s over one million > iterations. GOTO runs in about 1.42s for one million iterations. > So, the GOTO is about 10% faster, right? In this case, I would > use whatever version was in the standard lib. I personally don't have > code that iterates one million times, so it wouldn't matter. > However, 10% improvement is excellent. Alas, a difference of 0.15 > seconds is not likely to be noticed by your casual human observer. I had jeremy test the following version and he stated that it was 0.006s faster than the goto version. Admittedly very marginal, but none-the-less, we are comparing the speed of existing euphoria against gotos in euphoria. (Sorry for overstepping you Jeremy, but it would be unfair not to make the best comparison to something that is being argued as being faster.)
function factorial(atom a) atom b b = a while 1 do if a <= 2 then exit end if a = a - 1 b = b * a end while return b end function
Maybe this could be made even faster, I'm no speed freak. Chris Bensler Code is Alchemy