Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Fastest split possible

by Anonymous Monk
on Nov 07, 2019 at 01:14 UTC ( #11108411=note: print w/replies, xml ) Need Help??

in reply to Fastest split possible

Well, you do not tell us how huge your "huge string" is. But, even so, in these modern times I find it very difficult to imagine how any plausible difference of approach would actually make a human-measurable difference, therefore worth losing any coding-sleep about. All that being said, yes, your existing approach could be regarded as "expensive," such that in a legitimate edge-case you could perhaps justify replacing it with a loop based on either the string-position function or the "/g" regex modifier. But this decision should be guided by ... "are you in actual, measurable pain?"

Replies are listed 'Best First'.
Re^2: Fastest split possible
by Your Mother (Bishop) on Nov 07, 2019 at 02:31 UTC

    You really should try reading the previous answers before remarking. Trying a little harder to cover up your style will spare you 3 or 4 downvotes at this point as well; draws attention to the lack of answer.

Re^2: Fastest split possible
by jcb (Vicar) on Nov 08, 2019 at 01:04 UTC

    All you need is for scanning that string to be in an inner loop and you are screwed even on modern hardware. The questioner is asking about making split faster and has presumably already found that to be the limiting step in his program. There are already benchmarks in this discussion showing that the split builtin is about 4–5 times faster than any of the Perl equivalents the monks have suggested so far.

    If this is in an inner loop, yes, even a small difference could be the difference between "good enough" and user complaints that "it takes too long". The solution is probably to reorganize the program to ensure that the string is only scanned once, but if that is already the case, we may have a situation where data is arriving too fast for a single node to handle and we need to scale out into a cluster. The first step in that direction is always the hardest because adding the coordination overhead means you may need two or three nodes just to match what one node could previously handle. Of course you can then add more nodes once you have paid that cost, but this is getting way into "XY Problem" territory for this discussion.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11108411]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2020-10-22 21:56 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (230 votes). Check out past polls.