On Wed, 2011-06-08 at 10:26 +0100, Rouslan Placella wrote:
On Wed, 2011-06-08 at 09:41 +0200, Michal Čihař wrote:
Hi
Dne Tue, 07 Jun 2011 12:22:02 -0400 Marc Delisle marc@infomarc.info napsal(a):
I tested on a 64-bit Linux machine (running as a VM under ESX 4.1) under PHP 5.3.6-RC3 and got different results (for current master):
Binary search: 0.6088 array_search: 2.0246 isset: 0.0068 array_key_exists: 0.0176
I get similar numbers as well:
Binary search: 0.6937 array_search: 3.393 isset: 0.0056 array_key_exists: 0.0228
What is also interesting is worst results achieved during search for all words in the array:
Binary search: 1.3098 array_search: 4.0101 isset: 0.0333 array_key_exists: 0.0868
Both binary search and array_search give pretty inconsistent results.
For the flipped array you expect to call array_flip or change data structure to already contain flipped array? I assume latter, because otherwise overhead for flipping array would probably make results worse.
I think it doesn't matter if one calls array_flip or not as that function is implemented very efficiently in PHP and the time to execute it can be considered negligible.
Rouslan
Actually, I take that back, array_flip really sucks:
Binary search: 0.4924 array_search: 1.5532 isset + array_flip: 4.6791 isset on flipped array: 0.0043
Rouslan