Well, eval is clearly the looser, chr wins:
use Benchmark qw(cmpthese);
my $S = 'Compruebe si las direcciones URL que encontr\u00e9 en el arch
+ivo de configuraci\u00f3n son v\u00e1lidos';
cmpthese(1e6,
{
eval => sub { $_ = $S; s/\\u([0-9a-fA-F]{4})/eval "\"\\x{$1}\"
+"/ge; },
chr => sub { $_ = $S; s/\\u([0-9a-fA-F]{4})/chr hex $1/ge; },
pack => sub { $_ = $S; s/\\u([0-9a-fA-F]{4})/pack 'U', hex $1/
+ge; }
}
);
__END__
Rate eval pack chr
eval 38865/s -- -84% -88%
pack 242131/s 523% -- -28%
chr 336700/s 766% 39% --
# without eval
Rate pack chr
pack 242131/s -- -27%
chr 330033/s 36% --
which is reasonable, since chr is more specialized than pack and should have less overhead (otherwise chr would have been implemented in terms of pack).
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
|