But the results don't produce the expected difference.pl@nereida:~/Lperltesting$ cat comparequotedstrings.pl #!/usr/local/lib/perl/5.10.1/bin//perl5.10.1 use v5.10; use Benchmark qw{cmpthese}; # See http://www.regex-engineer.org/slides/img10.html my $regexp = qr/ " # double quote (?: # no memory [^"\\]++ # no " or escape: Don't backtrack | (?: \\.)++ # escaped character )*+ # Don't backtrack " # end double quote /x; my $bregexp = qr/ " # double quote (?: # no memory [^"\\]+ # no " or escape: backtrack | (?: \\.)+ # escaped character )* # backtrack " # end double quote /x; # input matches many times. Using "g" option my $input = (q{"abc\"defg"hijk}x10000); cmpthese( 0, { gbacktrack => q{ $input =~ /$bregexp/g }, gpossessive => q{ $input =~ /$regexp/g } } ); #input matches a long string, no g option $input = '"'.(q{abc\"defg}x10000).'"'; cmpthese( 0, { backtrack => q{ $input =~ /$bregexp/ }, possessive => q{ $input =~ /$regexp/ } } ); # input does not match. Using "g" option $input = '"'.("abcdefghijk"x10000); cmpthese( 0, { failgbacktrack => q{ $input =~ /$bregexp/g }, failgpossessive => q{ $input =~ /$regexp/g } } );
It seems as if there is no significant difference, even for the failing case. Am I doing something wrong?pl@nereida:~/Lperltesting$ ./comparequotedstrings.pl Rate gpossessive gbacktrack gpossessive 645439/s -- -1% gbacktrack 649435/s 1% -- Rate possessive backtrack possessive 694364/s -- -0% backtrack 696767/s 0% -- Rate failgpossessive failgbacktrack failgpossessive 649435/s -- -2% failgbacktrack 659647/s 2% -- pl@nereida:~/Lperltesting$
In reply to Possessive Quantifiers in Perl 5.10 regexps by casiano
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |