Bug #53887 [NEW]: When array data is int value, array_intersect() speed VERY SLOW.
| From: | paulgao at yeah dot net | Date: | Mon, 31 Jan 2011 07:19:57 +0000 |
| Subject: | Bug #53887 [NEW]: When array data is int value, array_intersect() speed VERY SLOW. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-158349@lists.php.net to get a copy of this message | ||
From:
Operating system: irrelevant
PHP version: Irrelevant
Package: Arrays related
Bug Type: Bug
Bug description:When array data is int value, array_intersect() speed VERY SLOW.
Description:
------------
When array data is int value, array_intersect() speed VERY SLOW.
Test script:
---------------
<?php
ini_set('memory_limit', -1);
$data_a = rand_data(FALSE);
$data_b = rand_data(FALSE);
$time = microtime(TRUE);
$result = array_intersect($data_a, $data_b);
$time = microtime(TRUE) - $time;
echo " -> array_intersect by intval: {$time}, result: " . count($result) .
"\r\n";
$data_a = rand_data(TRUE);
$data_b = rand_data(TRUE);
$time = microtime(TRUE);
$result = array_intersect($data_a, $data_b);
$time = microtime(TRUE) - $time;
echo " -> array_intersect by string: {$time}, result: " . count($result) .
"\r\n";
function rand_data($need_string)
{
mt_srand();
$result = array();
for ($i = 0; $i < 300000; $i++)
{
if ($need_string === TRUE)
{
$result[] = (string)mt_rand();
}
else
{
$result[] = mt_rand();
}
}
return $result;
}
?>
Expected result:
----------------
almost same?
Actual result:
--------------
-> array_intersect by intval: 10.661009073257, result: 47
-> array_intersect by string: 1.3067090511322, result: 41
--
Edit bug report at http://bugs.php.net/bug.php?id=53887&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53887&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53887&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53887&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53887&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53887&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53887&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53887&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53887&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53887&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53887&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53887&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53887&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53887&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53887&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53887&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53887&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53887&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53887&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53887&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53887&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53887&r=mysqlcfg