Skip to content

Instantly share code, notes, and snippets.

@cjfields
Created March 15, 2011 21:22
Show Gist options
  • Select an option

  • Save cjfields/871516 to your computer and use it in GitHub Desktop.

Select an option

Save cjfields/871516 to your computer and use it in GitHub Desktop.
Bio::SeqFeature speedup using caching and cloned instances
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