Re: Speed comparison of regex versus index, lc, and / /i




Quoth "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>:

Changing this to

while ( $text =~ /\Q$ss\E/og ) {

makes regex_find faster by about 1%.

my $rx = qr/\Q$ss/;

...

while ($text =~ /$rx/g) {

is both clearer and safer. If the program is modified so that $ss is
actually variable (say, the whole thing is made into a sub) then /o
would cause it to fail in ways that are rather hard to diagnose.

Note that m// will only use the precompiled form of the qr// if the
$rx is the only thing in the match. Something like /^$rx/ or
/$rx1|$rx2/ or even / $rx/x will cause the regex to be recompiled
every time all over again.

Ben

--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@xxxxxxxxxxxx
.



Relevant Pages

  • RE: Try FireFox browser it is better than IE
    ... Since it is faster, clearer, more stable and safer... ... It also does allow you to customize extensively with add-ons, ... place to surf eventually. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Base64 MIME
    ... It's cleaner, clearer, safer and supports io-layers. ... Redundancy is a great way to introduce more single points of failure. ...
    (comp.lang.perl.misc)
  • Re: Base64 MIME
    ... It's cleaner, clearer, safer and supports io-layers. ...
    (comp.lang.perl.misc)
  • Re: Disabling bracket substitution?
    ... It's safer for variable whitespace. ... It's intent is clearer. ...
    (comp.lang.tcl)