PHP browser detection script -- optimization suggestion
Forgive the nitpick-y nature of this optimization, as I am eternally grateful for this script's usefulness, however I suggest searching for all occurrences of the following type of FOR loop:
:: Code ::
//os tester for ( $i = 0; $i < count( $a_os ); $i++ ) in which the count() function is being used as the guard condition, and replacing each occurrence with something akin to the following: :: Code ::
//os tester $osCount = count($a_os); for ( $i = 0; $i < $osCount; $i++ ) By caching the the number of elements in the array, loop execution can be improved up to 50% by not having to call count() repeatedly. This was gleaned from section 28.2, Optimizing Loops, in Core PHP Programming, by Leon Atkinson and Zeev Suraski. -Chris Back to top |
|||||
ah, very nice, that's a habit i have, I didn't realize it would count it each time. No problem with the nitpicking, that's what makes code get better, thanks for letting me know about that aspect of the loop, I always assumed that was counted one time, then used.
Hardly nitpicking, a lot of time was spent on that trying to get it somewhat optimized over time. <check new versions, all loops are now pre counted rather than counting arrays.> Back to top |
|||||
All times are GMT - 8 Hours
|