On Jun 11, Steffen Mueller said:

>"Andy Bach" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
>[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>| and checking on perl's results found it sort of in the middle.
>| http://www.bagley.org/~doug/shootout/lang/perl/
>
>Come on. Without being the greatest of programmers, it took me five minutes
>to improve the performance of the Fibonacci numbers Perl algorithm by
>light-years!
>
>Who would use a recursive algorithm when performance and memory usage are
>critical?

Does recursive mean "calling yourself", or does it mean "building a huge
ugly stack by calling yourself"?  Because I can use goto &foo to alleviate
the stress.

  sub fib {
    my ($c, $s, $t) = ($_[0] - 1, $_[1] || 0, $_[2] || 1);
    return $t if $c == 0;
    @_ = ($c, $t, $t+$s);
    goto &fib;
  }

It CALLS itself, but with the benefit of avoiding a stack building up.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]

Reply via email to