note
vr
<p>I remember, some time ago, looking under the hood of [metamod://Algorithm::Combinatorics], to find it somewhat inefficient. The [metamod://ntheory] equivalents, if they exist, are faster:</p>
<c>
use ntheory 'forcomb';
sub Eily_LanX_vr {
my ( $length, $ones ) = @_;
my ( $str, $s, @r );
$str = '0' x $length;
forcomb {
$s = $str;
substr $s, $_, 1, '1' for @_;
push @r, $s;
} $length, $ones;
return \@r
}
cmpthese(-3, {
Eily_LanX_vr => sub { Eily_LanX_vr(25, 5) },
Eily_LanX => sub { Eily_LanX(25, 5) },
});
__END__
Rate Eily_LanX Eily_LanX_vr
Eily_LanX 11.9/s -- -59%
Eily_LanX_vr 29.0/s 143% --
</c>
11121888
11121908