Advanced PHP Optimization Tips (Chapter 2: Iterate over arrays)It's time to continue with my attempts to find which is the better (most optimized) way to program in PHP. In previous post I took a look at string concatenating. This time I'm going to iterate over arrays. The main goal is to get the key and the value of each item in an array. Let's start: Iterate over arrays test: This is the target array $values = array("a", "b", "c", "d", "e", "f"); and these are my test cases Case 1: Case 2: Case 3: Case 4: Case 2 is 3 times slower than Case 1 Case 3 is 1.5 times slower than Case 1 Case 4 is 1.5 times slower than Case 1 This result are not so spectacular as the result in string concatenating article, that's because reading a variable is faster than writing. Curious how much faster? So let't test this too. Bonus test results:
published on 16 nov 07 comments please sign in to be able to add comments! | tags recent posts | |||
Advanced PHP Optimization Tips (Chapter 2: Iterate over arrays) |