while ((my $begin, my $end) = each %exon_endpoints) { print get_exon($chromosome, $begin, $end), "\n\n"; } sub get_exon { my($chromosome, $begin, $end) = @_; # The arguments to substr are: string, beginning, length return substr($chromosome, $begin - 1, $end - $begin + 1); }
becomes ...
while ((my $begin, my $end) = each %exon_endpoints) { print substr($chromosome, $begin - 1, $end - $begin + 1), "\n\n"; }
Now, it's relatively obvious that the first option is the more readable, and the author says so, as well. The second, given a large enough $chromosome, is much faster.
I was wondering if there were other optimizations than passing by reference (as suggested in an earlier optimization option). The only one I could think of was to use closures, along the lines of:
my $chromosome; get_chromosome(1, \$chromosome); my $get_exon = sub { substr $chromosome, $_[0] - 1, $_[1] - $_[0] - 1; }; while (my @ends = each %exon_endpoints) { print $get_exon->(@ends), "\n\n"; }
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Large data processing ...
by liz (Monsignor) on Oct 16, 2003 at 17:44 UTC | |
by demerphq (Chancellor) on Oct 18, 2003 at 18:53 UTC | |
|
Re: Large data processing ...
by perrin (Chancellor) on Oct 16, 2003 at 18:01 UTC | |
|
Re: Large data processing ...
by BrowserUk (Patriarch) on Oct 16, 2003 at 22:02 UTC | |
|
Re: Large data processing ...
by Abigail-II (Bishop) on Oct 16, 2003 at 20:53 UTC |