Req #79545 [NEW]: mbstring functions are about 10x slower
From: michael dot vorisek at emailc dot z
Operating system: Linux
PHP version: 7.4.5
Package: Performance problem
Bug Type: Feature/Change Request
Bug description:mbstring functions are about 10x slower
Description:
------------
https://3v4l.org/bOdXP
Currently the performance difference between single-byte and multi-byte
string function is about 5x - 25x (yes, +400% - +2400%).
Please verify and comment.
If the performance can not be improved with mbstring, then checking if
the input string does contain only 0x00 - 0x7f chars will improve the
overall/real PHP performace - check can be done very quickly using
modern/vectored CPU instructions - and if satisfied, use equivalent
single-byte string function instead of multi-byte one.
Test script:
---------------
$cnt = 100000;
$strs = [
'empty' => '',
'short' => 'zluty kun',
'short_with_uc' => 'zluty Kun',
'long' => str_repeat('this is about 10000 chars long string', 270),
'long_with_uc' => str_repeat('this is about 10000 chars long
String', 270),
'short_utf8' => 'žlutý kůÅ',
'short_utf8_with_uc' => 'Žlutý kÅ®Å',
];
foreach ($strs as $k => $str) {
$a1 = microtime(true);
for($i=0; $i < $cnt; ++$i){
$res = strtolower($str);
}
$t1 = microtime(true) - $a1;
// echo 'it took ' . round($t1 * 1000, 3) . ' ms for ++$i'."\n";
$a2 = microtime(true);
for($i=0; $i < $cnt; $i++){
$res = mb_strtolower($str);
}
$t2 = microtime(true) - $a2;
// echo 'it took ' . round($t2 * 1000, 3) . ' ms for $i++'."\n";
echo 'strtolower is '.round($t2/$t1, 2).'x faster than mb_strtolower
for ' . $k . "\n\n";
}
Expected result:
----------------
strtolower is 6.73x faster than mb_strtolower for empty
strtolower is 9.78x faster than mb_strtolower for short
strtolower is 7.13x faster than mb_strtolower for short_with_uc
strtolower is 24.88x faster than mb_strtolower for long
strtolower is 23.12x faster than mb_strtolower for long_with_uc
strtolower is 9.05x faster than mb_strtolower for short_utf8
strtolower is 9.93x faster than mb_strtolower for short_utf8_with_uc
Actual result:
--------------
Difference should be no larger than 1.5x at least for single-byte
strings.
--
Edit bug report at https://bugs.php.net/bug.php?id=79545&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79545&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79545&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79545&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79545&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79545&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79545&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79545&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79545&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79545&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79545&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79545&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79545&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79545&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79545&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79545&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79545&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79545&r=mysqlcfg
Thread (5 messages)
- michael dot vorisek at emailc dot z