in reply to Re: Matching arrays?
in thread Matching arrays?

It should be noted that grep(/11/||/are/,@text) will be quite a bit faster in execution than grep(/11|are/),@text) because of the short circuit and constant regexpes.

Indeed, after a quick test I found:
#!/usr/bin/perl use Benchmark qw(timethese cmpthese); my @seed = ("Hi there 11", "Fred blamed me", "17 o clock", "It's snowi +ng hampsters", "Pickles are people too!"); @text = map {@seed[$_ % $#seed+1]}(0 .. 300); cmpthese -1 => { short_circuit => 'grep(/11/||/are/,@text)', alternate => 'grep(/11|are/,@text)', } __END__ bagelbox:~ josh$ perl testgrep Rate alternate short_circuit alternate 642/s -- -81% short_circuit 3309/s 416% --

Replies are listed 'Best First'.
Re: Re: Re: Matching arrays?
by ysth (Canon) on Mar 09, 2004 at 04:31 UTC
    I'd think that after a certain number of alternates the regex would be faster.