Seems like ne "" is what I was looking for. :)
Be careful. Anonymonk's benchmark is conflating an aweful lot of other stuff in with the actual code you are concerned about.
I believe (but I'm open to correction), this to be a far better benchmark, and it shows a radically different result. It might just set your mind at ease. (Or not!):
#!/usr/bin/perl --
use strict;
use warnings;
use Benchmark qw( cmpthese );
# Make bytes:: functions available, but use character semantics.
use bytes ();
our $smileys = "\x{263a}" x 10_000;
our $empty = "\x{263a}"; chop $empty;
cmpthese -1, {
bytes => q{
my $c=0;
( bytes::length($empty) or bytes::length($smileys) ) and ++$c
+for 1 .. 1000;
},
utf8 => q{
my $c=0;
( length($empty) or length($smileys) ) and ++$c for 1 .. 1000;
},
ord => q{
my $c=0;
( ord( $empty ) or ord( $smileys ) ) and ++$c for 1 .. 1000;
},
'ne""' => q{
my $c=0;
( $empty ne '' or $smileys ne '' ) and ++$c for 1 .. 1000;
},
};
__END__
C:\test>junk8
Rate bytes ord ne"" utf8
bytes 1379/s -- -72% -75% -76%
ord 4992/s 262% -- -10% -13%
ne"" 5566/s 304% 12% -- -3%
utf8 5757/s 317% 15% 3% --
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|