Re: Re: [PEPr] Comment on Networking::Monitor
| From: | Robert Peake | Date: | Thu, 09 Dec 2004 19:31:55 +0000 |
| Subject: | Re: Re: [PEPr] Comment on Networking::Monitor | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34977@lists.php.net to get a copy of this message | ||
Looks like getting array_keys() and array_values() and then looping through them in parallel is actually the fastest approach.
-RP
Joshua Eichorn wrote:
Bertrand Mansion wrote:Joe Stump wrote:I found the real home of that benchmark. http://www.blueshoes.org/en/developer/php_bench/ -joshIt depends on the use. foreach() for small arrays is supposed to be faster than while(list() each()). Also, you don't have to reset() arrays after using foreach(), BUT foreach() makes a *copy* to work on, which can be resource heavy with really large arrays (ie. you'd have two copies of a 200k length array if you used foreach()). This is what I understand to be the differences. Things may have changed since I last looked into this. --Joe On Dec 9, 2004, at 10:04 AM, Robert Peake wrote:As said by Joe, speed is the difference. With PHP5, you can now use reference for values instead of copying (but this will probably make your code not PHP4 compatible) as in foreach ($arr as &$value) So if the size of the array is not too big, feel free to use foreach instead :) BertrandHi Bertrand, Yes -- I will double-check CS before moving to vote. s/if(/if (/g <- my best friend :) Why do you recommend foreach instead of while ... each?