[PHP] Re: problem with large arrays in php 4.3.2

2006-01-22 Thread Jesse Guardiani
Jesse Guardiani jesse at wingnet.net writes:

 
 Hello,
 
 I have an old version of php (4.3.2) that is acting rather strangely. I'm
 searching two large arrays (approx 22,000 records in each) using
 array_diff_key() from the PEAR PHP_Compat library:
 
 $result = $args[0];
 foreach ($args[0] as $key1 = $value1) {
 for ($i = 1; $i !== $array_count; $i++) {
 foreach ($args[$i] as $key2 = $value2) {
 if ((string) $key1 === (string) $key2) {
 unset($result[$key2]);
 break 2;
 }
 }
 }
 }
 
 And I'm getting aweful performance. I know it's a ton of records (22,000 *
 22,000), but it shouldn't take 16 minutes on a P4 Xeon 2.4ghz!
 
 Has anyone seen this before? Is this a bug? Or are my math skills lacking and
 this is perfectly normal performance for the size of the data set?
 
 Thanks!


I've conducted a little multi-language benchmark to see how other languages
compare to PHP with regard to associative arrays of this size:
http://www.guardiani.us/index.php/Hash_Array_Benchmark

The result in short? PHP is a pretty typical performer, IMO.

Thanks!

P.S. Please read the disclaimer carefully before submitting criticism. Unless
you have a neat optimization to share or code from another language to
contribute, I've probably heard it already and don't care. :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: problem with large arrays in php 4.3.2

2006-01-11 Thread James Benson


Their should be no problem with what your trying to do, try the 
following function, should act pretty much like array_diff();





if(!function_exists('array_diff')) {
function array_diff($array1, $array2)
{
$difference = array();
foreach($array1 as $key = $value)
{
if(is_numeric($key)) {
if(!in_array($value, $array2)) {
$difference[] = $value;
}
} else {
if(!array_key_exists($key, $array2)) {
$difference[] = $key;
}
}
}
return $difference;
}
}




// small test
$array1 = array_fill(0, 2, 'banana');
$array2 = array();
print_r(array_diff($array1, $array2));




It also depends how much data the arrays contain

James



Jesse Guardiani wrote:

Hello,

I have an old version of php (4.3.2) that is acting rather strangely. I'm
searching two large arrays (approx 22,000 records in each) using
array_diff_key() from the PEAR PHP_Compat library:

$result = $args[0];
foreach ($args[0] as $key1 = $value1) {
for ($i = 1; $i !== $array_count; $i++) {
foreach ($args[$i] as $key2 = $value2) {
if ((string) $key1 === (string) $key2) {
unset($result[$key2]);
break 2;
}
}
}
}

And I'm getting aweful performance. I know it's a ton of records (22,000 *
22,000), but it shouldn't take 16 minutes on a P4 Xeon 2.4ghz!

Has anyone seen this before? Is this a bug? Or are my math skills lacking and
this is perfectly normal performance for the size of the data set?

Thanks!



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php