In my problem '01' is different than '10', and I need to count them separately. Still, your point of not needing to count the last is well taken, as I can count 3, and thereby know the 4th. However, by doing this, I'm not seeing any significant performance gains, and it may be a bit slower.
Rate browser+LR browserUK
browser+LR 19055/s -- -2%
browserUK 19509/s 2% --
Code for benchmarking...
#!/usr/bin/perl
use strict;
use Benchmark qw/cmpthese/;
cmpthese(
-3,
{
# orighash => sub { orighash(); },
# twolevel => sub { twolevel(); },
# substring => sub { substring(); },
# blokhead => sub { blokhead(); },
#blokchop => \&blokchop,
#orig => \&orig,
browserUK => \&browserUK,
"browser+LR" => \&browserLR,
#ikegami => \&ikegami,
}
);
sub browserUK {
my @strings = qw/111011001010011110100010100001
111010000010010110000010000001
000101011100001000110101110000
000101111101001001111101111110
111011001010111110100010100001
000100010100000000010001010000/;
for my $i ( 0 .. $#strings ) {
for my $j ( $i + 1 .. $#strings ) {
my @counts = (
( $strings[$i] | $strings[$j] ) =~ tr[0][0],
( ~$strings[$i] & $strings[$j] ) =~ tr[\1][\1],
( $strings[$i] & ~$strings[$j] ) =~ tr[\1][\1],
( $strings[$i] & $strings[$j] ) =~ tr[1][1]
);
}
}
}
sub browserLR {
my @strings = qw/111011001010011110100010100001
111010000010010110000010000001
000101011100001000110101110000
000101111101001001111101111110
111011001010111110100010100001
000100010100000000010001010000/;
for my $i ( 0 .. $#strings ) {
for my $j ( $i + 1 .. $#strings ) {
my @counts = (
( $strings[$i] | $strings[$j] ) =~ tr[0][0],
( ~$strings[$i] & $strings[$j] ) =~ tr[\1][\1],
( $strings[$i] & ~$strings[$j] ) =~ tr[\1][\1],
# ( $strings[$i] & $strings[$j] ) =~ t
+r[1][1]
);
$counts[3] = scalar(@strings) - $counts[0] - $counts[1] -
+$counts[2];
}
}
}
| [reply] [d/l] [select] |