[Phpmyadmin-devel] Is PMA_STR_binarySearchInArr needed?

Piotr Przybylski piotr.prz at gmail.com
Wed Jun 8 19:32:59 CEST 2011


2011/6/8 Rouslan Placella <rouslan at placella.com>:
> 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 at 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
>

Yes, it is slow.

For now, I pushed some changes to master:
- sqlparser.data.php is unchanged
- PMA_backquote uses in_array
- PMA_SQP_parse performs array_flip on required arrays and caches
results in a static variable (0.00037s for me)

I have still doubts about using flipped arrays in sqlparser.data.php.
On one hand, it's a few lines of code less in SQL parser and code is
still readable, on the other hand flipped arrays require additional 4
KB of code in sqlparser.data.php

-- 
Piotr Przybylski




More information about the Developers mailing list