VV
Size: a a a
VV
МИ
NK
YM
NK
YM
Use of this module for anything other than debugging purposes is strongly discouraged.
NK
NK
NK
VO
VO
VO
VO
YM
bytes::length()
is admittedly handy if you need to know the byte length of a Perl scalar. But a more modern way is:use Encode 'encode';
length(encode('UTF-8', $scalar))
VG
VG
NK
SU
SU
$ perl -MEncode -MBenchmark -E 'my$s="ы"x1e5;my$c=0;timethese(1e5,{encode=>sub{$c+=length(encode(utf8=>$s))},bytes=>sub{use bytes;$c+=bytes::length($s);no bytes}})'
Benchmark: timing 100000 iterations of bytes, encode...
bytes: 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) @ 10000000.00/s (n=100000)
(warning: too few iterations for a reliable count)
encode: 24 wallclock secs (16.76 usr + 6.78 sys = 23.54 CPU) @ 4248.09/s (n=100000)
SZ