in reply to Re^2: ASCII encoded unicode strings on web, such as \u00F3
in thread ASCII encoded unicode strings on web, such as \u00F3

So, I am curious, since chr hex is more efficient, then eval, is pack('U', hex) more efficient then chr hex or vice versa?
  • Comment on Re^3: ASCII encoded unicode strings on web, such as \u00F3

Replies are listed 'Best First'.
Re^4: ASCII encoded unicode strings on web, such as \u00F3
by shmem (Chancellor) on Jul 13, 2015 at 11:34 UTC

    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'