Bug #70754 [NEW]: array_udiff compares the same values multiple times
| From: | php_bugs at multiwebinc dot com | Date: | Wed, 21 Oct 2015 01:40:40 +0000 |
| Subject: | Bug #70754 [NEW]: array_udiff compares the same values multiple times | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196717@lists.php.net to get a copy of this message | ||
From: php_bugs at multiwebinc dot com
Operating system:
PHP version: 7.0.0RC5
Package: Performance problem
Bug Type: Bug
Bug description:array_udiff compares the same values multiple times
Description:
------------
All versions of PHP seem to be inefficient at executing array_udiff. The
values in $a in the callback function are all compared twice. If the
callback function is expensive, this would affect performance.
Also, some comparisons are unnecessary.
Test script:
---------------
/* Note: The callback function just returns 0 every time, which means
that all values in both arrays are considered equal. */
function callback($a, $b) {
echo "\$a = $a; \$b= $b; ";
echo "<br>\n";
return 0;
}
$array1 = array("first_0", "first_1", "first_2", "first_3",
"first_4"
);
$array2 = array("second_0", "second_1", "second_2",
"second_3",
"second_4");
$result = array_udiff($array1, $array2, "callback");
Actual result:
--------------
$a = first_2; $b= first_1;
$a = first_4; $b= first_2;
$a = first_2; $b= first_0;
$a = first_3; $b= first_2;
$a = first_4; $b= first_3; // Unnecessary since we already know these
are equal
$a = first_1; $b= first_0; // Unnecessary since we already know these
are equal
$a = second_2; $b= second_1;
$a = second_4; $b= second_2;
$a = second_2; $b= second_0;
$a = second_3; $b= second_2;
$a = second_4; $b= second_3; // Unnecessary since we already know these
are equal
$a = second_1; $b= second_0; // Unnecessary since we already know these
are equal
$a = first_4; $b= second_4;
$a = first_4; $b= first_3; // Duplicate. Already tested above.
$a = first_3; $b= first_2; // Duplicate. Already tested above.
$a = first_2; $b= first_1; // Duplicate. Already tested above.
$a = first_1; $b= first_0; // Duplicate. Already tested above.
--
Edit bug report at https://bugs.php.net/bug.php?id=70754&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70754&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70754&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70754&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70754&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70754&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70754&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70754&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70754&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70754&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70754&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70754&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70754&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70754&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70754&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70754&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70754&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70754&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70754&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70754&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70754&r=mysqlcfg