Ironically, the recursive form (just leave out "goto") is *much* faster. It's a little hard to tell using factorial, but you can see it in this:
sub rec_max {
return () unless @_;
my ($h1, $h2) = (shift, shift);
if (@_) {
unshift @_, ($h1 > $h2) ? $h1 : $h2;
&rec_max; # Try it with and without goto here
}
elsif (defined $h2) {
return ($h1 > $h2) ? $h1 : $h2;
}
}
use List::Util 'shuffle';
print rec_max shuffle(1..2000,1500..3000,3500..8000);
Maybe someone else can explain that.
Caution: Contents may have been coded under pressure.
|