I wrote this program to compare the efficiency of Perl 5.10 possesive quantifiers (++, *+, etc.) against the ordinary operators:

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 } } );
But the results don't produce the expected difference.
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$
It seems as if there is no significant difference, even for the failing case. Am I doing something wrong?

In reply to Possessive Quantifiers in Perl 5.10 regexps by casiano

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.