in reply to Re^2: Not sure what I am doing wrong
in thread Not sure what I am doing wrong

Even then, the less alternations you have the faster your regex will run. Of course if the strings or patterns have nothing in common it makes no difference.

I did a quick test and got the following results:

Rate Raw Regex Assembled Regex Raw Regex 614/s -- -9% Assembled Regex 676/s 10% --
The text to check was part of a play by Shakespeare, loaded into an array (1 line per element) and the regex used was
qr /this|that|here|there|where/;
Assembled into a more efficient regex it looks like:
qr /(?:th(?:ere|at|is)|w?here)/
Even by eliminating only ONE of the alternations (5 vs 4) a 10% speed-up was obtained.

PS: I do not know about 5.10, this was tested in 5.8.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^4: Not sure what I am doing wrong
by massa (Hermit) on Nov 26, 2008 at 14:34 UTC