-
-
Save anonymous/2914d6494253eec53f91 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/env perl | |
use strict; | |
use warnings; | |
use Benchmark qw(:all) ; | |
my $line = "ACGT" x 1_000_000; | |
my @order = qw(A C G T); | |
sub counting_with_regexp { | |
my %nucleotides = ( | |
A => 0, | |
C => 0, | |
G => 0, | |
T => 0, | |
); | |
for my $letter ( keys( %nucleotides ) ) { | |
$nucleotides{$letter} += ( () = $line =~ /$letter/g ); | |
} | |
} | |
sub counting_with_substr { | |
my %nucleotides; | |
for my $i (0..length($line)) { | |
my $char = substr($line,$i,1); | |
$nucleotides{$char}++; | |
} | |
} | |
timethese(10, { | |
"counting with regexp" => \&counting_with_regexp, | |
"counting with substr" => \&counting_with_substr, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment