Thomas, Mark - BLS CTR wrote, on Tuesday, April 11, 2006 10:28 AM : $Bill Luebkert wrote: : > Rate RE2 RE5 RE3 RE4 RE1 RE1a : > RE2 136761/s -- -58% -61% -64% -74% -74% : > RE5 326584/s 139% -- -6% -14% -37% -37% : > RE3 347705/s 154% 6% -- -9% -33% -33% : > RE4 381098/s 179% 17% 10% -- -26% -26% : > RE1 516529/s 278% 58% 49% 36% -- -0% : > RE1a 516529/s 278% 58% 49% 36% 0% -- : > : > 1 $str =~ s/\s(?=\s*\S)/0/og; : > 1a $str =~ s/\s(?=\s*\S)/0/g; : > 2 1 while ($str =~ s/\s(?=(\d|\.))/0/); : > 3 $str =~ s/^(\s+)(?=\d)/'0' x (length $1)/e; : > 4 $str =~ s/^(\s+)/sprintf "%s", q[0]x length($1)/eg; : > 5 $str =~ s/ (?=.*\d)/0/g; : : What surprises me is the substantial difference between the : lookahead expressions, RE1a and RE5. Can anyone explain why : there's such a difference?
I think I can explain it. When (5) sees the .*\d, the .* grabs all the characters, then the RE engine backs up until it "releases" a digit to match the \d. (1a), on the other hand, just grabs spaces with \s*; it isn't allowed to grab anything else. Perhaps a (5a), having .*?\d, thus making the engine stop at every character to see if it's a digit before adding it to the .*?, would bring it more into line with (1a) speed-wise. Joe Joseph Discenza, Senior Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300 Fax: 574.243.6060 _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs