in reply to Help tightening up a subroutine please
I am willing to bet your grep is the slowest bit, but have you profiled the code? Anyhow, assuming the grep bit is your bottleneck:
## your original code @{$sets{$fasta_id}[$setscounter]{$sitekey}} = grep { $_ >= $lowerlimit and $_ <= $upperlimit } @{$matches{$fasta_id}{$sitekey}};
Depending on your data, you may gain some performance by using a sorted array instead:
@{$sets{$fasta_id}[$setscounter]{$sitekey}} = (); foreach ( sort @{$matches{$fasta_id}{$sitekey}} ) { last if $_ > $upperlimit; next if $_ < $lowerlimit; push @{$sets{$fasta_id}[$setscounter]{$sitekey}}, $_; }
This will only have an advantage if sort is sufficiently fast and there are many elements above $upperlimit, so this suggestion comes with an extreme case of "know thy data".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help tightening up a subroutine please
by mdunnbass (Monk) on Jan 23, 2007 at 20:32 UTC | |
by radiantmatrix (Parson) on Jan 24, 2007 at 22:16 UTC |