in reply to RE: Re: is split optimized?
in thread is split optimized?

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