in reply to Re: multiple greps at once-- possible?
in thread multiple greps at once-- possible?
Since you're not actually using the set of values generated by each grep, but only want to test whether there is such a match, it might (depending on the sizes of the arrays and how often called) be useful to write your tests as a short-circuiting foreach:Whether 'grep' or a short circuiting for is faster doesn't depend on how often you call it (although it matters whether it's significant). The size of the array plays a role, but what's more important is whether there is a match, and if there is, where the first match is. 'grep' wins if there's no match, or if the match is at the end. In the past, I've done some benchmarking, and found that the short circuit method was faster if the first match was to be found in about the first two-thirds of the list. I've also found noticable differences in the cut-off point when doing exact matching (==) or regex matching (=~) - differences I've not been able to explain.
But with different versions of Perl, you might get different results. My point is that deciding whether the replace a grep with a short-circuiting for loop is not an easy decision.
Abigail
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: multiple greps at once-- possible?
by ccn (Vicar) on Apr 08, 2004 at 20:49 UTC | |
Re: Re: multiple greps at once-- possible?
by Roy Johnson (Monsignor) on Apr 08, 2004 at 17:39 UTC |