Benchmarking proved that the second version is about 50% slower than the first & simple one.
Intresting. I know regexes are expensive, but I expect that the second version will scale better. If the number of chars in $word1 is N1, and the number of chars in $word2 is N2, then I think the first version would be O(N1N2)--pretty bad. The second one should be simply O(N1), though it depends on how the regex is implemented internaly.
In reply to Re: Optimizing a string processing sub
by hardburn
in thread Optimizing a string processing sub
by spurperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |