KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
First of all, I understand in 90% of applications the performance difference is completely irrelevant, but I just need to know which is the faster construct. That and... The information currently available on them on the net is confusing. A lot of people say foreach is bad, but technically it should be faster since it's suppose to simplify writing a array traversal using iterators. Iterators, which are again suppose to be faster, but in PHP are also apparently dead slow (or is this not a PHP thing?). I'm talking about the array functions: next() prev() reset() etc. well, if they are even functions and not one of those PHP language features that look like functions. To narrow this down a little : I'm not interesting in traversing arrays in steps of anything more than 1 (no negative steps either, ie. reverse iteration). I'm also not interested in a traversal to and from arbitrary points, just 0 to length. I also don't see manipulating arrays with more than 1000 keys happening on a regular basis, but I do see a array being traversed multiple times in the logic of a application! Also as for operations, largely only string manipulation and echo'ing. Here are few reference sites: http://www.phpbench.com/ http://www.php.lt/benchmark/phpbench.php What I hear everywhere: foreach is slow, and thus for / while is faster PHPs foreach copies the array it iterates over; to make it faster you need to use references code like this: $key = array_keys($aHash); $size = sizeOf($key); for ($i=0; $i < $size; $i++) is faster than a foreach Here's my problem. I wrote this test script: http://pastebin.com/1ZgK07US and no matter
Tags (comma-separated)
Save Edits
Cancel