Created
March 15, 2011 21:22
-
-
Save cjfields/871516 to your computer and use it in GitHub Desktop.
Bio::SeqFeature speedup using caching and cloned instances
This file contains hidden or 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
| cjfields@pyrimidine:~/tests/seq$ cat locations_bm.pl | |
| #!/usr/bin/perl -w | |
| use Modern::Perl; | |
| use Bio::SeqIO; | |
| use Benchmark qw(cmpthese); | |
| my $file = shift; | |
| cmpthese(10, { | |
| 'default' => \&default_location, | |
| 'cached' => \&cached | |
| }); | |
| my $ct1 = my $ct2 = 0; | |
| sub default_location { | |
| my $in = Bio::SeqIO->new(-file => $file, | |
| -format => 'genbank'); | |
| while (my $seq = $in->next_seq) { | |
| for my $sf ($seq->get_SeqFeatures) { | |
| next unless $sf->primary_tag eq 'CDS'; | |
| } | |
| } | |
| } | |
| sub cached { | |
| my $in = Bio::SeqIO->new(-file => $file, | |
| -format => 'genbank'); | |
| $in->location_factory->cache(1); | |
| while (my $seq = $in->next_seq) { | |
| for my $sf ($seq->get_SeqFeatures) { | |
| next unless $sf->primary_tag eq 'CDS'; | |
| } | |
| } | |
| } | |
| cjfields@pyrimidine:~/tests/seq$ perl locations_bm.pl NC_014922.txt | |
| s/iter default cached | |
| default 2.08 -- -26% | |
| cached 1.54 35% -- | |
| cjfields@pyrimidine:~/tests/seq$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment