Re: why a.pl is faster than b.pl
- From: cdevers@xxxxxxxxx (Chris Devers)
- Date: Thu, 29 Dec 2005 10:11:19 -0500 (EST)
On Thu, 29 Dec 2005, Bob Showalter wrote:
> Jeff Pang wrote:
> > Hi,bob,
> >
> > You said:
> >
> > 3. It will probably be faster to use a single regex of the format:
> >
> > /pata|patb|patc|patd/
> >
> >
> > In fact maybe you are wrong on this.
>
> Darn. First time this year :-)
>
> > Based on my test case,the RE written as below:
> >
> > /pata/ || /patb/ || /patc/ || /patd/
> >
> > is much faster than yours.
>
> OK. Perhaps its due to backtracking. Go with what works!
Several Perl books, including _Mastering Regular Expressions_ and, if I
remember correctly, _Learning Perl_, use variants of this example. In
essence, yes, if you want to match one of several constant strings like
this, the match will happen faster with a series of static regexes than
it would wwith one compound regex with alternation.
--
Chris Devers
DO NOT LEAVE IT IS NOT REAL
.
- References:
- Re: why a.pl is faster than b.pl
- From: Jeff Pang
- Re: why a.pl is faster than b.pl
- From: Bob Showalter
- Re: why a.pl is faster than b.pl
- Prev by Date: Re: why a.pl is faster than b.pl
- Next by Date: Re: getting a number out of a string....
- Previous by thread: Re: why a.pl is faster than b.pl
- Next by thread: Processing a web page (or looping over a multi line string)
- Index(es):