note 102208 added to function.in-array
| From: | user at NOSPAM at fullservicead dot com | Date: | Wed, 02 Feb 2011 16:52:10 +0000 |
| Subject: | note 102208 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176600@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 74.59.92.152
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/102208
Del: integrated -- https://master.php.net/note/delete/102208/integrated
Del: useless -- https://master.php.net/note/delete/102208/useless
Del: bad code -- https://master.php.net/note/delete/102208/bad+code
Del: spam -- https://master.php.net/note/delete/102208/spam
Del: non-english -- https://master.php.net/note/delete/102208/non-english
Del: in docs -- https://master.php.net/note/delete/102208/in+docs
Del: other reasons-- https://master.php.net/note/delete/102208
Reject -- https://master.php.net/note/reject/102208
Search -- https://master.php.net/manage/user-notes.php