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

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.

  • Comment on Re^3: Why does global match run faster than none global?

Replies are listed 'Best First'.
Re^4: Why does global match run faster than none global?
by ikegami (Patriarch) on Aug 23, 2011 at 20:52 UTC
    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.
        Finding that "456789" doesn't contain "23" can be done in nanoseconds.