in reply to Re: using s/// as map?
in thread how can I speed up this perl??

This should be a little better.
++$count{$1} while $genome =~ /\G(..)/g;
The PerlMonks advocate for tr///

Replies are listed 'Best First'.
Re^3: using s/// as map?
by thospel (Hermit) on Nov 24, 2003 at 19:46 UTC
    You're only doing half the work now :-)

    You can make it work like this though:

    ++$count{$1},pos($genome)-- while $genome =~ /\G(..)/g
    It's interesting that this is slightly faster than dropping the \G.

    This however turns out to be a lot slower (seems to do a complete linear search for the proper string start every time):

    $genome =~ /./g; $count{$1}++ while $genome =~ /(.\G.)/g

    update This however means that the lookahead version can be speeded up by about 5% too:

    $count{$1}++ while $genome =~ /\G(?=(..))./g
      You're only doing half the work now :-)
      But if I understand gene work (not a certainty at all), I'm doing the half they actually want to do. :-P A molecule isn't paired with both of its neighbors, they are grouped two-by-two.

      At least now I understand why they were doing the lookahead.

      The PerlMonks advocate for tr///