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% --
In reply to Re^3: Alternative to bytes::length()
by BrowserUk
in thread Alternative to bytes::length()
by creamygoodness
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |