note 106404 added to function.mb-convert-encoding
| From: | qdb at kukmara dot ru | Date: | Mon, 07 Nov 2011 15:44:54 +0000 |
| Subject: | note 106404 added to function.mb-convert-encoding | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184316@lists.php.net to get a copy of this message | ||
mb_substr and probably several other functions works faster in ucs-2 than in utf-8. and utf-16 works
slower than utf-8. here is test, ucs-2 is near 50 times faster than utf-8, and utf-16 is near 6
times slower than utf-8 here:
<?php
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('utf-8');
$s='ÑкгезÓÓ©ÑÓ©Ñ
зÓÑ
Ó©Ñк2049һһлдÑбÑÑÑÑмииÑÑиÑ.иÑбÒÑаÑÑ'
.'лдÑÑвÓÓÑүйÓÑйүÓÑ034928348539857ÓÑаÑдлаÑоÑаÑÒ»Ò»ÑлоавÑ';
$s.=$s;
$s.=$s;
$s.=$s;
$s.=$s;
$s.=$s;
$s.=$s;
$s.=$s;
$t1=microtime(true);
$i=0;
while($i<mb_strlen($s)){
$a=mb_substr($s,$i,2);
$i+=2;
if($i==10)echo$a.'. ';
//echo$a.'. ';
}
echo$i.'. ';
echo(microtime(true)-$t1);
echo'<br>';
$s=mb_convert_encoding($s,'UCS-2','utf8');
mb_internal_encoding('UCS-2');
$t1=microtime(true);
$i=0;
while($i<mb_strlen($s)){
$a=mb_substr($s,$i,2);
$i+=2;
if($i==10)echo mb_convert_encoding($a,'utf8','ucs2').'. ';
//echo$a.'. ';
}
echo$i.'. ';
echo(microtime(true)-$t1);
echo'<br>';
$s=mb_convert_encoding($s,'utf-16','ucs-2');
mb_internal_encoding('utf-16');
$t1=microtime(true);
$i=0;
while($i<mb_strlen($s)){
$a=mb_substr($s,$i,2);
$i+=2;
if($i==10)echo mb_convert_encoding($a,'utf8','utf-16').'. ';
//echo$a.'. ';
}
echo$i.'. ';
echo(microtime(true)-$t1);
?>
output:
Ó©Ñ
. 12416. 1.71738100052
Ó©Ñ
. 12416. 0.0211279392242
Ó©Ñ
. 12416. 11.2330229282
----
Server IP: 93.93.89.9
Probable Submitter: 78.138.176.205
----
Manual Page -- http://www.php.net/manual/en/function.mb-convert-encoding.php
Edit -- https://master.php.net/note/edit/106404
Del: integrated -- https://master.php.net/note/delete/106404/integrated
Del: useless -- https://master.php.net/note/delete/106404/useless
Del: bad code -- https://master.php.net/note/delete/106404/bad+code
Del: spam -- https://master.php.net/note/delete/106404/spam
Del: non-english -- https://master.php.net/note/delete/106404/non-english
Del: in docs -- https://master.php.net/note/delete/106404/in+docs
Del: other reasons-- https://master.php.net/note/delete/106404
Reject -- https://master.php.net/note/reject/106404
Search -- https://master.php.net/manage/user-notes.php