in reply to perl performance vs egrep
How about if you do a two-stage process of elimination: (please see the 'Update' first).
while( <IFILE> ) { next unless m/^[CKMPSWY]/; print OFILE unless /^(?:CP|K[LM]|ME|P[AM]|S[LZ]|WX|YZ)XX1/; }
This sort of "optimization" is highly sensitive to the type of data, however, if lines starting with [CKMPSWY] are sparse, it will reject non-matches much faster.
Update: Uggh, my logic is backwards in that snippet. The point is that if you can reject non-matches earlier, with fewer cycles, you save a little time.
I also wanted to mention the "print late" philosophy. If you're IO bound, you might be better off storing a few dozen lines in a scalar and printing just once every few-dozen iterations instead of on every iteration. This will maximize the effectiveness of the OS's buffering.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl performance vs egrep
by demerphq (Chancellor) on Jan 24, 2005 at 13:57 UTC | |
by ysth (Canon) on Jan 25, 2005 at 09:32 UTC | |
by demerphq (Chancellor) on Jan 25, 2005 at 17:56 UTC | |
by ysth (Canon) on Jan 25, 2005 at 19:37 UTC |