|
-
Aug 25th, 2010, 01:34 AM
#1
Thread Starter
Hyperactive Member
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?
-
Aug 25th, 2010, 03:39 AM
#2
Frenzied Member
Re: foreach fails. faster iterations?
-
Aug 25th, 2010, 11:57 AM
#3
Thread Starter
Hyperactive Member
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.
-
Sep 13th, 2010, 05:54 PM
#4
Lively Member
Re: foreach fails. faster iterations?
I wonder if ++$i < $i_ceil is faster than $i++ <= i_ceil?
-
Sep 21st, 2010, 04:27 PM
#5
Thread Starter
Hyperactive Member
Re: foreach fails. faster iterations?
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|