more useful options | |
PerlMonks |
Re^3: Apply A Set Of Regexes To A Stringby tachyon (Chancellor) |
on Oct 12, 2004 at 06:11 UTC ( [id://398377]=note: print w/replies, xml ) | Need Help?? |
One of the main benefits of alternation is that you can compile the RE. Essentially an alternation RE is very similar to the loop, but the loop code has been optimised to the task and is in C with alternation, but generalised and less efficient if you do it in perl. The difference is significant, at least that is what this Benchmark shows.....
But if I change that to a more real world situation by making the string a 14Kb one (approximately a web page size)
And now the loop is faster. In fact try this case:
~This is a purpose designed worst case for alternation as it requires continouous back tracking. So I have shattered my own delusions! Perl loops are faster than RE alternation. cheers tachyon
In Section
Seekers of Perl Wisdom
|
|