in reply to More benchmarks and stuff
in thread is split optimized?

I don't feel like mucking in the perl source code right now, so my guess as to why this is, has nothing to do with the way regex's or splits actually process the data, but rather that split is probably receiving a copy of the data, whereas regex is receiving a reference.

No, it has to do with what split and regex produce, not with what they get (behind the scenes, everything is a reference anyway). The regex only has to create a short new string, while the split (even if there's a split into 2 fields) has to create a large new string. And that's taking time.

So, if you have a gigantic string, and you only want the first, short field, a regex is the way to go. But usually you encounter short strings, and that's when split works better, despite itself using a regex. (But a much simpler regex, and it even might be that the case of " " is optimized itself too).

-- Abigail

Replies are listed 'Best First'.
The conclusion of: More benchmarks and stuff
by gryng (Hermit) on Jul 15, 2000 at 02:25 UTC
    Thanks Abigail, that sounds reasonable enough to believe! :)

    Ciao,
    Gryn