array_diff() takes over 3000 times longer than php 5.2.4
| Bug #47643 | array_diff() takes over 3000 times longer than php 5.2.4 | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2009-03-13 11:49 UTC | Modified: | 2010-11-01 18:18 UTC |
|
||||||||||
| From: | viper7 at viper-7 dot com | Assigned: | felipe (profile) | |||||||||||
| Status: | Closed | Package: | Performance problem | |||||||||||
| PHP Version: | 5.*, 6CVS (2009-04-13) | OS: | * | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2009-03-13 11:49 UTC] viper7 at viper-7 dot com
Description:
------------
This bug was reported in ##php on freenode, and after some thorough testing on multiple machines we determined it must be an engine bug.
array_diff on two large arrays of md5 hashes (600,000 elements each) takes approximately 4 seconds on a fast server in PHP 5.2.4 and below (confirmed with PHP 5.2.0), but over 4 hours (!) on PHP 5.2.6 and greater (confirmed with PHP 5.2.9 and PHP 5.3.0 beta2)
Reproduce code:
---------------
<?php
$i=0; $j=500000;
while($i < 600000) {
$i++; $j++;
$data1[] = md5($i);
$data2[] = md5($j);
}
$time = microtime(true);
echo "Starting array_diff\n";
$data_diff1 = array_diff($data1, $data2);
$time = microtime(true) - $time;
echo 'array_diff() took ' . number_format($time, 3) . ' seconds and returned ' . count($data_diff1) . " entries\n";
?>
Expected result:
----------------
Starting array_diff
array_diff() took 3.778 seconds and returned 500000 entries
Actual result:
--------------
Starting array_diff
array_diff() took 14826.278 seconds and returned 500000 entries
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-06-30 15:22 UTC] derick@php.net
[2009-07-01 15:32 UTC] dmitry@php.net
[2009-07-09 20:38 UTC] jani@php.net
[2010-01-17 12:09 UTC] emiel dot bruijntjes at copernica dot com
[2010-02-17 20:53 UTC] maarten at talkin dot nl
[2010-04-16 22:20 UTC] sylvain at jamendo dot com
[2010-08-04 05:21 UTC] lonnyk at gmail dot com
[2010-11-01 18:18 UTC] felipe@php.net
-Status: Assigned +Status: Closed
[2010-11-01 18:18 UTC] felipe@php.net
[2011-02-23 14:56 UTC] jaromir dot dolecek at skype dot net
[2014-11-28 14:39 UTC] samantha at adrichem dot nu
[2014-11-28 14:47 UTC] samantha at adrichem dot nu