Okay, I re-ran the benchmark with your exact code on my computer, and I got:
Benchmark: timing 1000000 iterations of index, s///, substr... index: 15 wallclock secs (14.02 usr + 0.00 sys = 14.02 CPU) @ 71 +326.68/s (n=1000000) s///: 13 wallclock secs (12.33 usr + 0.00 sys = 12.33 CPU) @ 81 +103.00/s (n=1000000) substr: 14 wallclock secs (13.37 usr + 0.00 sys = 13.37 CPU) @ 74 +794.32/s (n=1000000) Rate index substr s/// index 71327/s -- -5% -12% substr 74794/s 5% -- -8% s/// 81103/s 14% 8% --
So I guess it must be highly platform-dependent then. I'm using perl 5.8.0 on Mac OS X (darwin 6.3) on a PPC G3 (iBook).

Assuming you're using x86, a possible explanation would be that doing regex might benefit from the PPC's rich number of general-purpose registers, while the x86's memory-oriented instruction set is perhaps more suited at executing the (stack-based) perl opcodes.

But it's just a guess...

•Update: I'm enclosing all my benchmark stuff in readmore-tags to avoid cluttering the thread


In reply to Re: Re: Re: Re: Regex matching on anywhere but the beginning or end of a line by xmath
in thread Regex matching on anywhere but the beginning or end of a line by Anonymous Monk

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.