2011/6/7 Marc Delisle marc@infomarc.info:
Piotr Przybylski a écrit :
Hi,
For some time I was curious whether PMA_STR_binarySearchInArr is needed at all, and my test showed that there are faster (sometimes much faster) alternatives. Test for 100 000 iterations on PHP 5.3.4 (Windows, i5 2,53 GHz core):
PMA_STR_binarySearchInArr: 2.6606s array_search: 1.8936s isset: 0.0102s array_key_exists: 0.0934s
Isset and array_key_exists require flipped array, but array_search is a drop-in replacement that works faster, even though it does a linear search. Code used to perform this test is at [1].
Looking for different strings gives me different results. For example, looking for "BOTH" and array_search() is faster that PMA_STR_binarySearchInArr().
I searched for 'WRITE' to get an almost-worst case scenario with linear search, but I didn't expect results for array_search on other machines to be that much different.