Update: Everything in this node is based on a silly mistake and is irrelevant. The readmore has my original lunatic ramblings.

dragonchild's statement above is correct. chr(0) is a touch less efficient than "\0" or just plain 0 it seems, but not nearly so much as to make any difference in the real world. Still, the tests pass with the wrong string. The version of the benchmark and test code I grabbed from an earlier node must've reinforced my blunder.

Isn't chr(0) a null byte? Are you not on an ASCII machine? It should be the same, and should be saving a call.

If you need eq to work as well as ==, then it's a simple matter of "\0" instead of '\0'.

Also, if you're going to insist on using chr() here, use bytes::chr() instead, as that's the point use use bytes;.

Update:

[chris@localhost perl]$ perl -e '$foo = q{\0}; $bar = chr(0); print "m +atch!\n" if $foo eq $bar;'
[chris@localhost perl]$ perl -e '$foo = q{\0}; $bar = chr(0); print "m +atch!\n" if $foo == $bar;' match!
[chris@localhost perl]$ perl -e '$foo = qq{\0}; $bar = chr(0); print " +match!\n" if $foo eq $bar;' match!

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