foreach fails. faster iterations?
For discussion;
I've read up on (and performed my own) benchmarking for lengthy tasks and their faster functional equivalencies in PHP. Often it's said that micro-optimizing code is a worthless task, but I figure; sort them out before deployment to minimize code maintenance if the project grows.
A common one is foreach vs. various. foreach often fails in efficiency. Now, in my tests (and I've not seen this method much) when you want to iterate straight through an array, the following works the fastest:
PHP Code:
$i_ceil = count($my_array);
while($i++ <= $i_ceil){
//process on $my_array[$i]
}
Has anyone encountered faster? Has anyone found this approach unfeasible?
Re: foreach fails. faster iterations?
Re: foreach fails. faster iterations?
Oh I have already, thank you Zach_VB6. In fact, I've considered creating my own site for that purpose, complete user submissions, discussion, and multiple interpreted language categories.
I actually found in my testing (on many runs) that the while(){} iterator is several hundred times faster than foreach and it's equally slow counterparts. I'll post my brief analysis later this afternoon.
Re: foreach fails. faster iterations?
I wonder if ++$i < $i_ceil is faster than $i++ <= i_ceil?
Re: foreach fails. faster iterations?
Quote:
Originally Posted by
squared
I wonder if ++$i < $i_ceil is faster than $i++ <= i_ceil?
Haven't tested, wouldn't think there would be a difference though. They're identical except in timing.