in reply to Re: Why does global match run faster than none global?
in thread Why does global match run faster than none global?

Cause you're using an old(ish) version of Perl?

Rate b a c d b 3778652/s -- -1% -19% -21% a 3817631/s 1% -- -18% -20% c 4677165/s 24% 23% -- -2% d 4766254/s 26% 25% 2% --

This is perl 5, version 14, subversion 0 (v5.14.0) built for i686-linux-thread-multi

Replies are listed 'Best First'.
Re^3: Why does global match run faster than none global?
by BrowserUk (Patriarch) on Aug 23, 2011 at 20:56 UTC

    Even more intriguing. The slowest has hardly changed, but the previously faster ones have slowed markedly.

    C:\test\perl-5.14.0-RC1>perl use Benchmark qw[ cmpthese ];; print $];; $str = '123456789'; cmpthese -1, { a=>q[ my ($a,$b) = $str =~ m/(23)[^8]+(8)/g; ], b=>q[ my ($a,$b) = $str =~ m/(23)[^8]+(8)/; ], c=>q[ my ($a) = $str =~ m/(23)/g ], d=>q[ my ($a) = $str =~ m/(23)/; ], };; ^Z 5.014000 Rate b a d c b 363518/s -- -17% -35% -46% a 435446/s 20% -- -22% -35% d 555991/s 53% 28% -- -17% c 668598/s 84% 54% 20% --

    But still, 20% is not to be sneezed at.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Why does global match run faster than none global?
by Kc12349 (Monk) on Aug 23, 2011 at 20:33 UTC

    I'm running strawberry v5.12.3 built for MSWin32-x86-multi-thread. What confuses me, is that by its nature /g seems like it should run longer.

      Why would it take longer? All the /g version does in addition to the non-/g version is check if "9" is "23". Actually, it doesn't even get that far. It knows a minimum of 4 chars is needed for another match, yet there's only one char left.
        Fair enough, but in the case of searching for m/(23)/, /g will continue to the end of the string, while none /g should stop after its match. In this case it still seems like /g should be slower, though surely I could confused or missing something.
Re^3: Why does global match run faster than none global?
by BrowserUk (Patriarch) on Aug 25, 2011 at 04:12 UTC

    You did ensure that $str was defined as our not my didn't you?