I have one more optimization for you MeowChow.
Inside your _min() and _max()
subroutines, if the test returns false, it
reassigns the original value back to itself. You can
get around a 25% speed increase in the algorithm if you
only assign the $_ value to $max or
$min if it passes the test.
Here's a short benchmark that illustrates the difference
better:
#!/usr/bin/perl -w
use Algorithm::Numerical::Shuffle qw(shuffle);
use Benchmark qw(cmpthese);
#Randomize the array contents
my @array = shuffle 0..1000;
cmpthese(-3, {
max_dkubb1 => sub { max_dkubb1(@array) },
max_tilly => sub { max_tilly(@array) },
});
sub max_dkubb1 {
my $max = shift;
$max < $_ and $max = $_ for @_;
return $max;
}
sub max_tilly {
my $max = shift;
$max = $max < $_ ? $_ : $max for @_;
return $max;
}
On my system the max_dkubb1() routine
runs just over 25% faster than the other.