Created
October 10, 2009 00:22
-
-
Save kidd/206452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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