Bug #74933 [NEW]: MBstring functions are much slower when called with encoding parameter

From: Date: Mon, 17 Jul 2017 01:08:58 +0000
Subject: Bug #74933 [NEW]: MBstring functions are much slower when called with encoding parameter
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210077@lists.php.net to get a copy of this message
From: reinir dot puradinata at gmail dot com Operating system: Windows PHP version: 7.1.7 Package: mbstring related Bug Type: Bug Bug description:MBstring functions are much slower when called with encoding parameter Description: ------------ Several MBstring functions are much slower when called with encoding parameter than without encoding parameter. Functions that exhibit this behavior are mb_strlen, mb_substr, mb_strpos, mb_strrpos. For more information see: https://stackoverflow.com/questions/45028018/a/45107408 Test script: --------------- mb_internal_encoding("UTF-8"); echo "without encoding parameter:\n"; $a = microtime(true); for($i=0; $i<100000; $i++){ $n = mb_strlen("あえいおう"); } $a = microtime(true)-$a; echo "- mb_strlen: ".number_format($a*1000)." ms\n"; echo "\nwith encoding parameter:\n"; $b = microtime(true); for($i=0; $i<100000; $i++){ $n = mb_strlen("あえいおう", "UTF-8"); } $b = microtime(true)-$b; echo "- mb_strlen: ".number_format($b*1000)." ms (".number_format(($b-$a)*100/$a)."% slower)\n"; Expected result: ---------------- Because the character encoding is UTF-8 in both cases, I expected to see similar performance. In other words, 0% slower or close to it. Actual result: -------------- When called with encoding parameter, performance drops greatly. Example output from the test script: without encoding parameter: - mb_strlen: 14 ms with encoding parameter: - mb_strlen: 585 ms (4,186% slower) -- Edit bug report at https://bugs.php.net/bug.php?id=74933&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74933&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74933&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74933&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74933&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74933&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74933&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74933&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74933&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74933&r=support Expected behavior: https://bugs.php.net/fix.php?id=74933&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74933&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74933&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74933&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74933&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74933&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74933&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74933&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74933&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74933&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74933&r=mysqlcfg

« previous php.bugs (#210077) next »