Bug #74935 [Asn->Csd]: mb_str*pos functions do not take into consideration mb_internal_encoding

From: Date: Sun, 23 Jul 2017 11:00:15 +0000
Subject: Bug #74935 [Asn->Csd]: mb_str*pos functions do not take into consideration mb_internal_encoding
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210230@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74935&edit=1 ID: 74935 Updated by: nikic@php.net Reported by: andxfiles at gmail dot com Summary: mb_str*pos functions do not take into consideration mb_internal_encoding -Status: Assigned +Status: Closed Type: Bug Package: mbstring related Operating System: All PHP Version: Irrelevant Assigned To: nikic Block user comment: N Private report: N New Comment: A number of performance improvements for mb_stripos have been implemented. Output of your test code on PHP 7.1: mb_strlen with parameter UTF8: 38.2 milliseconds mb_stripos with parameter UTF8: 705.8 milliseconds mb_substr with parameter UTF8: 42.3 milliseconds mb_strlen with mb_internal_encoding UTF8: 15.1 milliseconds mb_stripos with mb_internal_encoding UTF8: 663.6 milliseconds mb_substr with mb_internal_encoding UTF8: 20.9 milliseconds Output on master: mb_strlen with parameter UTF8: 12.4 milliseconds mb_stripos with parameter UTF8: 83.4 milliseconds mb_substr with parameter UTF8: 19.5 milliseconds mb_strlen with mb_internal_encoding UTF8: 11.7 milliseconds mb_stripos with mb_internal_encoding UTF8: 82.4 milliseconds mb_substr with mb_internal_encoding UTF8: 17.8 milliseconds For your particular example this gives an approximately 8x improvement. Whether these changes will be in PHP 7.2 is yet to be seen. Previous Comments: ------------------------------------------------------------------------ [2017-07-17 08:50:38] andxfiles at gmail dot com Description: ------------ when calling mb_str*pos (stripos, strrpos etc.) functions using mb_internal_encoding before their call instead of passing the encoding as a parameter, those functions do not use the encoding provided, thus being way slower. As one can see in the actual results below, when using mb_internal_encoding, all functions become way faster except for mb_stripos. Test script: --------------- <?php $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά", "UTF-8"); } $finishtime = microtime(true); echo "mb_strlen with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0, "UTF-8"); } $finishtime = microtime(true); echo "mb_stripos with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1, "UTF-8"); } $finishtime = microtime(true); echo "mb_substr with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; mb_internal_encoding("UTF-8"); $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά"); } $finishtime = microtime(true); echo "mb_strlen with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0); } $finishtime = microtime(true); echo "mb_stripos with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1); } $finishtime = microtime(true); echo "mb_substr with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; ?> Actual result: -------------- mb_strlen with parameter UTF8: 103.7 milliseconds mb_stripos with parameter UTF8: 1450.7 milliseconds mb_substr with parameter UTF8: 81.6 milliseconds mb_strlen with mb_internal_encoding UTF8: 39.2 milliseconds mb_stripos with mb_internal_encoding UTF8: 1435.3 milliseconds mb_substr with mb_internal_encoding UTF8: 48.5 milliseconds ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74935&edit=1

« previous php.bugs (#210230) next »