Reply to Re: how are php arrays indexed?

Your name:

Reply:


Posted by Schraalhans Keukenmeester on 05/16/07 12:49

At Wed, 16 May 2007 04:01:37 -0700, Taras_96 let his monkeys type:

> Hi everyone,
>
> I'm wondering if anyone knows whether PHP does some indexing behind
> the scenes to make array searches faster.
>
> What I have is an array of around 100 000 elements, and I have a list
> of 1000 given element which I need to see whether they contained in
> the array. This means 1000 searches on an array of size 100 000. I'm
> hoping that PHP indexes it's keys using a binary tree or
> something.. :)
>
> Thanks
>
> Taras

Just gave your example a test run with two arrays full of random values
using array_intersect. On my localhost it takes about 2.45 seconds, so
you have an idea of the order of magnitude.

$myarray = array();
for ($i=0;$i<100000;$i++) {
$myarray[]=mt_rand(0,1000000);
}
$mytestarray = array();
for ($i=0;$i<1000;$i++) {
$mytestarray[]=mt_rand(0,10000);
}

$start = microtime(true);
$result=array_intersect($myarray,$mytestarray);
$stop = microtime(true);
echo $stop-$start; // avg 2.45 secs on P4-3200MHz, PHP sapi/Apache

The returned array still has the keys of the first array's matching
locations. Whether you get a large intersection or not doesn't seem to be
of great influence.

How much memory do you have available to your PHP scripts? If I make the
original array 150.000 elements 16Mb doesn't suffice anymore in above
example. If your data is more complex than my ints, this might become an
issue.

Rgds
Sh.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация