in reply to Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
Ok /(foo|bar)/ disables a bunch of optimizations that /foo/ || /bar/ can take advantage of. In fact the later can benefit from boyer-moore matching which means it may not have to read the full input stream to tell that the words arent present. However, this wont really scale up, slight modifications of the latter make them also disable the optimisations, and once you start looking at lots of patterns I think you will find that alternate techniques such as Regex::PreSuf, Regexp::Optimizer, Regexp::Assemble or Regexp::List will probably start becomming competitive.
However its worth noting that its very possible that future versions of perl will have optimizations that will make /(foo|bar)/ faster than /foo/ || /bar/. Whatever performance tuning you do will be just that, tuning for your particular enviornment.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
by JollyJinx (Acolyte) on Feb 18, 2005 at 14:42 UTC | |
by kvale (Monsignor) on Feb 18, 2005 at 16:44 UTC |