in reply to Re: Speed of simple pattern count. A comparison
in thread Speed of simple pattern count. A comparison

Also, it seems to me that 'x' should be prepended and appended to all the strings.

I prepended and appended it only to "split_by" variation, it should guarantee that the amount of returned chunks is +1 of amount of separators (split pattern occurrences). I think it is not relevant for other variations.
  • Comment on Re^2: Speed of simple pattern count. A comparison

Replies are listed 'Best First'.
Re^3: Speed of simple pattern count. A comparison
by jwkrahn (Abbot) on Jan 07, 2024 at 21:16 UTC

    Most of your tests use a 30,000 character string but your "split_by" test uses a 30,002 character string so the tests are not exactly equivalent.

    Just saying ...     :)

    Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
      I agree, this one test uses +2 more characters, but it is like included in the test as a tool.
      But now I think the first 'x' which is prepended is simply redundant, because if the string starts with "ab", it anyways gives an empty string as a leftmost result. The appended 'x' is not redundant, because if the string ends with pattern "ab", then it doesn't produce an empty string as a rightmost result. But here comes 'split' with three parameters with third being '-1', and then there is no need to append something like 'x'.