Skip to content

Instantly share code, notes, and snippets.

@kidd
Created October 10, 2009 00:22
Show Gist options
  • Save kidd/206452 to your computer and use it in GitHub Desktop.
Save kidd/206452 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use Benchmark qw(:all);
use Algorithm::Loops qw(Filter);
system('rm /tmp/footable.txt');
system('seq 1 2000 >>/tmp/footable.txt') for (1..4);
system('sed -i s/$/_i02_c00\ foo/ /tmp/footable.txt');
cmpthese (50, {
'filterChomp' =>
'open my $fh, "/tmp/footable.txt";
my %hash = map {
$_ => 1
} Filter {s/_i\d+_c\d+ .*$//} Filter{chomp} <$fh>;
close $fh; ' ,
'regexBarraN' =>
'open my $fh, "/tmp/footable.txt";
my %hash = map {
$_ => 1
} Filter {s/_i\d+_c\d+ .*\n//} <$fh>;
close $fh;' ,
'match' =>
' open my $fh, "/tmp/footable.txt";
my %hash = map {
$_ => 1
} Filter {m/^([^ ]*)_i\d+_c\d+/} <$fh>;
close $fh; ' ,
'while' =>
' open my $fh, "/tmp/footable.txt";
my %hash;
while (<$fh>) {
m/^([^ ]*)_i\d+_c\d+ .*/;
$hash{$1}=1;
}
close $fh;' ,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment