I had the clever idea of using vec. The Perl code is quite beautiful IMO, but it's slow as a snail.
sub using_vec { my ($s1, $s2) = @_; vec($s1, $_, 8) ||= vec($s2, $_, 8) for 0 .. length($s1)-1; return $s1; } sub using_str_bit_ops_and_s { my ($s1, $s2) = @_; (my $mask = $s1) =~ tr/\x00/\xFF/c; return ($s1 & $mask) | ($s2 & ~$mask); } my $x = pack 'C*', map int rand(256), 1 .. 64*1024; my $y = pack 'C*', map 1+int rand(255), 1 .. 64*1024; using_str_bit_ops_and_s($x, $y) eq using_vec($x, $y) or die "Results a +re different??"; use Benchmark 'cmpthese'; cmpthese -3, { using_str_bit_ops_and_s => sub{ my $r = using_str_bit_ops_and_s($x, +$y) }, using_vec=> sub{ my $r = using_vec($x, $y) }, };
Results:
Rate using_vec using_str_bit_o +ps_and_s using_vec 51.8/s -- + -92% using_str_bit_ops_and_s 672/s 1196% + --
12 times slower than ikegami's code I use as a reference implementation.

In reply to Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer) by bart
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.