Bug #80348 [NEW]: 10.000% inneficiency when using array_intersect_key and array_intersect_ukey
| From: | gilperon at gmail dot com | Date: | Tue, 10 Nov 2020 15:00:48 +0000 |
| Subject: | Bug #80348 [NEW]: 10.000% inneficiency when using array_intersect_key and array_intersect_ukey | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-230251@lists.php.net to get a copy of this message | ||
From: gilperon at gmail dot com
Operating system: All
PHP version: 7.4.12
Package: *General Issues
Bug Type: Bug
Bug description:10.000% inneficiency when using array_intersect_key and array_intersect_ukey
Description:
------------
Please run the test script. In my computer it outputs this:
1-> 0.0002131462097168
2-> 0.02832914352417
It's a 10.000% difference (100 * 0.0002 / 0.02) when using 2 supposedly
very similar functions, with only a small difference that one allows a
callback to be used.
I really need to use
array_intersect_ukey but the performance hit is
huge. I tried creating my own PHP implementation of
array_intersect_ukey and it runs a lot faster, but still is much
slower than array_intersect_key and I really need something similar to
array_intersect_key in terms of speed (it can even be 10x slower, but
not 100x or worse.
Test script:
---------------
<?php
$a = array();
$b = array();
for ($i=0;$i<1000;$i++) {
$a[$i] = true;
$b[2*$i + 1] = true;
}
$z = microtime(true);
for ($i=0;$i<10;$i++) {
$temp = array_intersect_key($a,$b);
}
echo "\n 1-> " . (microtime(true) - $z);
$z = microtime(true);
for ($i=0;$i<10;$i++) {
$temp = array_intersect_ukey($a,$b,function($key1,$key2) {
if ($key1 === $key2) {
return 0;
}
else{
return $key2 - $key1;
}
});
}
echo "\n 2-> " . (microtime(true) - $z);
?>
Expected result:
----------------
Both functions should run at similar speeds.
Actual result:
--------------
One function runs 10.000% slower than the other.
--
Edit bug report at https://bugs.php.net/bug.php?id=80348&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80348&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80348&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80348&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80348&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80348&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80348&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80348&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80348&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80348&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80348&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80348&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80348&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80348&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80348&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80348&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80348&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80348&r=mysqlcfg