camel

�Ϥä�����äƤ���ϥե����ǤϤʤ���

�ߤ�����: Erlang��Perl��®�����
Perl¦�ϡ�Encode���٤��� Encode::from_to��inplace�ǥ���С��Ȥ��Ƥ��ޤ�����ˡ�ľ����ʸ���󥳥ԡ�������Τ�ƶ����Ƥ���Τ���

�ʤ��ʤ顢Encode::from_to()��®�٤ǤϤʤ����������˺�Ŭ�����Ƥ��뤫�顣

���⤽��Ϥ��ᤫ��UTF-8�������utf8�ե饰�����äƤ���ʸ�����from_to��Ȥ��ΤϤФ����Ƥ��롣

for(my $i = 0; $i < 0xffff; $i++) {
        my $str2 = $str;
        Encode::from_to($str2, "UTF-8", "Shift_JIS");
}

��ñ��

for my $i (0..0xffff) {
    Encode::encode("Shift_JIS", $str);
}

�Ǥ褤��

�����������ξ��Ϥ�����Ŭ��ǤϤʤ���Encode�Ǥ�ʸ��������̾��̾�����⤷�Ƥ��뤫�����"sjis"��"Shift_JIS"��Ʊ���˰�������ˤϡ������ʤ�餫�η��Ǥ���餬Ʊ���Ǥ��뤳�Ȥ�Ƚ�ꤷ�ʤ���Фʤ�ʤ��������ô���Τ���Encode::find_encoding()����

�¤Ϥ���Encode::find_encoding()���֤��Τ����������줿̾���ǤϤʤ����֥������ȤǤ��롣�����ơ��¤ΤȤ������Υ��֥������Ȥ������ºݤ�(en|de)code��Ԥ�transcoder�ʤΤǤ��롣��äƺ�Ŭ��ϡ��ʲ��ΤȤ���Ȥʤ롣

my $enc = find_encoding("Shift_JIS");
for my $i (0..0xffff) {
    $enc->encode($str);
}

�ʾ���̣������Ǽ¹Ԥ��Ƥߤ��Τ����ʲ���benchmark�Ǥ��롣

            Rate   E::ft  U::J n Jcode n  U::J s Jcode s    E::e    E OO
E::ft    27655/s      --    -35%    -40%    -57%    -58%    -58%    -81%
U::J n   42639/s     54%      --     -7%    -34%    -35%    -35%    -71%
Jcode n  45809/s     66%      7%      --    -29%    -30%    -30%    -69%
U::J s   64725/s    134%     52%     41%      --     -1%     -1%    -56%
Jcode s  65330/s    136%     53%     43%      1%      --     -0%    -56%
E::e     65333/s    136%     53%     43%      1%      0%      --    -56%
E OO    148025/s    435%    247%    223%    129%    127%    127%      --

# Where
# E::ft    Encode::from_to
# U::J n   Unicode::Japanese->new for each iteration
# Jcode n  Jcode->new for each iteration
# U::J s   Unicode::Japanese with object reuse
# Jcode s  Jcode with object reuse
# E::e     Encode::encode
# E OO     Encode with object reuse

Benchmark�Υ�������Ǹ��ź�դ��Ƥ������ΤǾܤ����Ϥ��������ĺ���Ȥ��ơ������̤�Encode��Ŭ�ڤ˻Ȥ��Ф��ʤ��®�ʤΤǤ��롣

�ȤϤ�����ΤΡ�find_encoding()��Ȥä��ƥ��˥å��ϰճ��Ȥޤ��Τ��Ƥ��ʤ��Τǡ�����򵡲�˾Ҳ𤷤Ƥߤ���Encode 2.20�Ǥ⤳�Υƥ��˥å���POD�ǾҲ𤷤Ƥ��롣

Happy Encoding!

Dan the Encode Maintainer

use strict;
use warnings;
use Benchmark qw/cmpthese timethese/;
use utf8;
use Encode;
use Jcode;
use Unicode::Japanese;

my $str = join '', ( 'a' .. 'z', ( map { chr } ord('��') .. ord('��') ) );
my $bytes = encode_utf8($str);
my $uj    = Unicode::Japanese->new;
my $j     = Jcode->new;
my $e     = find_encoding('sjis');

cmpthese(
    timethese(
        0,
        {
            'U::J n' =>
              sub { Unicode::Japanese->new( $str, 'utf8' )->sjis },
            'U::J s'  => sub { $uj->set( $str,   'utf8' )->sjis },
            'Jcode n' => sub { Jcode->new( $str, 'utf8' )->sjis },
            'Jcode s' => sub { $j->set( $str,    'utf8' )->sjis },
            'E::ft'   => sub {
                my $b2 = $bytes;
                Encode::from_to( $b2, "UTF-8", "Shift_JIS" );
            },
            'E::e' => sub { encode( 'sjis', $str ) },
            'E OO'     => sub { $e->encode($str) },
        }
    )
);