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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |