This trivial one is basically Moritz version implemented with 'split'. But it comes up as #3. For some reason 'index' is twice as fast in the rate limiting step.

Some crazy ideas I won't write code for:
- misusing internal variables, e. g. $RS
- grep (most likely a slow 2 pass to get the list)
- rindex (Moritz backwards)
- unpack (Instead of split)
- printf
- vec
- ikegami_tr with Bit::Vector
sub nijo { use bytes; my ($s1, $s2) = @_; my $idx = 0; my $len; my @chunks = split /\0/, $s1; foreach my $chunk (@chunks) { $len = length($chunk); substr ($s2, $idx, $len) = $chunk; $idx = $idx + 1 + $len; } return $s2; }
Rate split1 substr1 ikegami_s avar corion avar2 nijo ike +gami_tr moritz split1 3.07/s -- -84% -86% -99% -99% -99% -99% + -99% -100% substr1 19.4/s 532% -- -8% -95% -96% -96% -96% + -96% -98% ikegami_s 21.2/s 590% 9% -- -95% -95% -95% -96% + -96% -98% avar 410/s 13254% 2013% 1834% -- -8% -8% -20% + -25% -59% corion 445/s 14383% 2192% 1998% 8% -- -0% -13% + -19% -56% avar2 446/s 14428% 2199% 2004% 9% 0% -- -13% + -19% -56% nijo 514/s 16640% 2549% 2324% 25% 16% 15% -- + -6% -49% ikegami_tr 549/s 17784% 2730% 2490% 34% 23% 23% 7% + -- -46% moritz 1009/s 32749% 5098% 4658% 146% 127% 126% 96% + 84% -- 1..9 ok 1 - corion gets some value ok 2 - substr1 gets same value ok 3 - split1 gets same value ok 4 - moritz gets same value ok 5 - nijo gets same value ok 6 - ikegami_tr gets same value ok 7 - ikegami_s gets same value ok 8 - avar gets same value ok 9 - avar2 gets same value

In reply to Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer) by NiJo
in thread Challenge: CPU-optimized byte-wise or-equals (for a meter of beer) by dragonchild

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.