the regex $str =~ /foo/ devolves to something pretty much like Index $str, 'foo'

Yes exactly. Itll be a little slower than a index but only becuase there is a longer codepath from the regex-opcode to the actual FBM search than from the index-opcode.

The surprise is how fast using a character set with a common prefix match is. That result also goes a long way to validating the benchmark.

And it illustrates a new optimisation in 5.10:

Rate using_alt_match using_or_nomatch using_alt_ +nomatch using_or_match using_alt_match 412710/s -- -29% + -30% -36% using_or_nomatch 580306/s 41% -- + -1% -9% using_alt_nomatch 585631/s 42% 1% + -- -9% using_or_match 640118/s 55% 10% + 9% -- 1631660

Basically 5.10 is smart enough to convert /baz|bar/ into something close to /ba[rz]/. Its not quite as fast when written as an alternation due to current implmentation details, but it is very close.

---
$world=~s/war/peace/g


In reply to Re^2: Benchmarking regex alternation by demerphq
in thread Benchmarking regex alternation by Tanktalus

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.