in reply to Re: Re: speeding up regex
in thread speeding up regex

You could try replacing

$count++ while $text =~ /$gene/g; # Count number of instances
with
$count = () = $text =~ /$gene/g;

It may run a little quicker. You could also try

my $p=0; ++$count while $p = 1+index( $text, $gene, $p );

Which may be quicker still.

If your process takes a long time to run, the obvious thing to do to save having to wait for the whole thing to complete before you can get a feel for which is quickest would be too use a small subset of the data whilst testing. If the text being search comes from a file, try using head to grab the first couple of hundred lines of the real data and use that for performance testing the options.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller