in reply to Re: Why is goto &sub slow?
in thread Why is goto &sub slow?

That doesn't gibe. Here's the two sequences, as I understand them.

Standard recursion:

  1. First call to func(). (Create first frame on the stack)
  2. Second call to func(). (Create second frame on the stack)
  3. Return from second call. (Destroy second frame on the stack)
  4. Return from first call. (Destory first frame on the stack)

goto ⊂

  1. First call to func(). (Create first frame on the stack)
  2. goto ⊂ (Destory first frame, create first frame)
  3. Return from goto call. (Destory first frame)

I count two creations and two destructions of a stack frame. What am I missing? Plus, since goto ⊂ doesn't have such a large stack, it takes less memory and lookups take less time. Right?

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Replies are listed 'Best First'.
Re: Re: Re: Why is goto &sub slow?
by kvale (Monsignor) on Mar 29, 2004 at 02:26 UTC
    From L-R's updated benchmark and from your benchmark, recursion is only 2-10 percent faster than goto &sub. As you say above, both recursion and goto &sub create and destroy two frames. So the results seem consistent to me. Unless you are refering to that 10 percent slowdown for goto &sub? I don't know what is happening there.

    -Mark