UTF-8フラグを落とすのはどれが早いのか 
Wednesday, January 26, 2011, 07:49 AM - Programing, Programing / Perl
Posted by Administrator
Perl 5.8以降導入されたUTF-8フラグを落とすのはどれが早いのか

#!/usr/bin/perl
use Benchmark;
use Encode;

while(<STDIN>){
$gplv2 .= $_;
}
utf8::decode($gplv2);

timethese(
1000000,
{
"utf8::encode" =>sub(){
my $s = $gplv2;
utf8::encode($s);
return();
},
"Encode::encode" =>sub(){
my $s = Encode::encode("utf8",$gplv2);
return();
},
"Encode::encode_utf8" =>sub(){
my $s = Encode::encode_utf8($gplv2);
return();
}
}
);

STDINへぶち込むのはGPLv2 日本語訳全文
> Benchmark: timing 1000000 iterations of Encode::encode, Encode::encode_utf8, utf8::encode...
> Encode::encode: 14 wallclock secs (11.13 usr + 0.01 sys = 11.14 CPU) @ 89766.61/s (n=1000000)
> Encode::encode_utf8: 7 wallclock secs ( 5.56 usr + 0.01 sys = 5.57 CPU) @ 179533.21/s (n=1000000)
> utf8::encode: 4 wallclock secs ( 2.41 usr + 0.00 sys = 2.41 CPU) @ 414937.76/s (n=1000000)
圧勝過ぎワロタ
1 comment ( 1572 views )   |  permalink

<<First <Back | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next> Last>>