I agree that I was not comparing the equivalent (in work requested to be done) code. However my point was to submit code that (plainly) only got the first arguement, in order to show how much more work split was doing. As pointed out later, by btrott and nardo, adding split's third arguement brings it back up to regex's speed, but that is because they are now doing an equivalent amount of work.

I answered Anonymous Monks's question of wether "perl optimize(s) the split and only grab the first field" with the line: ($y) = (split(/\s+/,$x))[0]; To which the answer is no. But as I conceeded to btrott, he (and nardo) had the "correct" answer, of saying that you need to add a third arguement to get split to only do the first match.

Appreciately, you probably responded because I used regex's in my example and you did not want Anonymous Monk to mistakenly think that regex's were faster than split. However I do not think he took it that way, rather his post seemed to convey an understanding of all of what I just mentioned above (minus the fact that we did not know/remember about the third arguement in split).

Anyway, this is mainly here to clear up the comment in the chatterbox about benchmark being a hammer. I was only using it to show, fairly concretely, that split was not stopping after the first match. I didn't mean to imply that it couldn't.

Cheers,
Gryn


In reply to Apples, Oranges, and Fruit by gryng
in thread is split optimized? 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.