[Pdx-pm] string comparison vs hash
Austin Schutz
tex at off.org
Tue May 29 15:35:07 PDT 2007
On Tue, May 29, 2007 at 01:52:25PM -0700, Thomas J Keller wrote:
> {
> 'with_string_cmp' => sub {
> my $names_join = join '|', @names;
> my @goi;
> if ($fh1->open("< $annot_file")) {
> my @lines = <$fh1>;
> foreach (@lines) {
> chomp;
> push @goi, $_ if $_ =~ m/($names_join)/;
> }
> } else { die "Could not get the filehandle $fh1: $!." }
> $fh1->close;
> },
>
> 'with_hash' => sub {
> my %have_name = map({$_ => 1} @names);
> if ($fh2->open("< $annot_file")) {
> my $header = <$fh2>;
> while(my $line = <$fh2>) {
> my ($name,$else) = split(/\t/, $line, 2);
> $have_name{$name} = [split(/\t/, $else)]
> or next;
> }
> } else { die "Could not get the filehandle $fh2: $!." }
> $fh2->close;
> }
> });
>
> I think this is a fair comparison.
You are using different file reading techniques. That could be
_very_ significant. If you are going to slurp all the lines for the
string comparison you should do the same for the hash.
Austin
More information about the Pdx-pm-list
mailing list