ID: 47221 Updated by: fel...@php.net Reported By: sgnutzmann at yahoo dot de Status: Verified Bug Type: Arrays related Operating System: win32 only - Windows XP PHP Version: 5.2.8 New Comment:
See bug #47643 Previous Comments: ------------------------------------------------------------------------ [2009-08-31 16:42:06] sjo...@php.net Could reproduce. This code shows the time taken to array_diff two arrays for the builtin array_diff and for a PHP function fast_array_diff I wrote. <?php $a = $b = array(); for ($i = 0; $i < 10000; $i++) { $a[] = "s" . ($i * 102121 % 433061); $b[] = "s" . ($i * 102121 % 433003); } $start = microtime(true); $res1 = array_diff($a, $b); echo "Built-in array_diff duration: ".(microtime(true) - $start)."\n"; include('http://www.gissen.nl/files/fast_array_diff.php'); $start = microtime(true); $res2 = fast_array_diff($a, $b); echo "Fast_array_diff duration: ".(microtime(true) - $start)."\n"; sort($res1); sort($res2); assert($res1 == $res2); ?> Output: Built-in array_diff duration: 11.8710849285 Fast_array_diff duration: 0.254959106445 ------------------------------------------------------------------------ [2009-02-08 13:03:18] j...@php.net Please don't send me more spam. (never saw that and any direct mails to me will be deleted anyway) ------------------------------------------------------------------------ [2009-01-27 13:55:35] sgnutzmann at yahoo dot de I just try the latest version 'php-5.2-win32-VC6-x86-latest.msi' (2009-Jan-27 12:00:00). This version has the same problem as PHP 5.2.8 (no return in 5 minutes from array_diff(), infinite loop?). I sent my test dataset 'TestData.txt' to j...@php.net. ------------------------------------------------------------------------ [2009-01-27 12:09:33] sgnutzmann at yahoo dot de PHP 5.2.6 has the same problem as PHP 5.2.8 ------------------------------------------------------------------------ [2009-01-27 10:32:48] sgnutzmann at yahoo dot de Complete test script (size of generated test file 5,865 KB) <?php $handle = fopen('TestData.txt','rb'); // size of first array $buffer = fgets($handle, 256); $buffer = str_replace("\r",'',$buffer); $buffer = str_replace("\n",'',$buffer); $count = (int) $buffer; echo 'Size of first array: '.$count."\r\n"; // elements of first array $idSales = array(); for ( $i = 0; $i < $count; $i++ ) { $buffer = fgets($handle, 256); $buffer = str_replace("\r",'',$buffer); $buffer = str_replace("\n",'',$buffer); $idSales[] = $buffer; } // for ( $i = 0; $i < $count; $i++ ) // size of second array $buffer = fgets($handle, 256); $buffer = str_replace("\r",'',$buffer); $buffer = str_replace("\n",'',$buffer); $count = (int) $buffer; echo 'Size of second array: '.$count."\r\n"; // elements of second array $idInv = array(); for ( $i = 0; $i < $count; $i++ ) { $buffer = fgets($handle, 256); $buffer = str_replace("\r",'',$buffer); $buffer = str_replace("\n",'',$buffer); $idInv[] = $buffer; } // for ( $i = 0; $i < $count; $i++ ) fclose($handle); echo "Start of array_diff\r\n"; $unknown = array_diff ( $idSales, $idInv ); echo 'Number of unknown identifier '.count($unknown)."\r\n"; ?> First lines of test file: 76906 #00/1109 #00/1162 #00/1163 #00/1335 #00/1337 Result, if I use PHP 5.2.4: Size of first array: 76906 Size of second array: 433959 Start of array_diff Number of unknown identifier 17826 No result from array_diff, if I use PHP 5.2.8 (without any extension) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/47221 -- Edit this bug report at http://bugs.php.net/?id=47221&edit=1