note 102208 deleted from function.in-array by cmb
| From: | cmb@php.net | Date: | Sun, 15 Sep 2019 13:14:18 +0000 |
| Subject: | note 102208 deleted from function.in-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212204@lists.php.net to get a copy of this message | ||
Note Submitter: user at NOSPAM at fullservicead dot com
----
After reading all other notes about performance,
I made a little test.
fill an array in a loop with random characters,
shuffle it
search on it using 4 methods.
I tried to have haystack as array and string; hence the strstr.
I tried it on 9, 99, 999, 9999 elements and the results
remain in the same order:
9999 elements
Function : execution time in miliseconds.
strstr : 1.2994079589844
fast_in_array : 1.0655579566956
isset : 0.99128198623657 //Winner, used from another note here.
in_array : 2.9410798549652
One last detail, I moved my functions around in the script to make sure there was no memory caching,
reiteration op or whatever, it's all the same. in_array is the slowest and the use of
isset($array[$NEEDLE]) the fastest.
I hope it saves somebody else the trouble.