Let’s look at a common php ‘optimization’ tip (note that I am only running this test on my computer, and I am not shutting things down to help it go faster).
Use single quotes ( ‘ ) instead of double quotes ( ” ) .
The reasoning behind this is that php parses double quoted strings for variables, so it takes way longer to process your evil double quoted strings than it does to parse your single quoted strings.
$test = 'something'; $repeats = 1000000; $start1 = microtime(true); $first = ''; for($i = 0; $i < $repeats; $i ++){ $first .= 'string '. $test; } $end1 = microtime(true); $time1 = ($end1 - $start1); $start2 = microtime(true); $second = ""; for($i = 0; $i < $repeats; $i ++){ $second .= "string $test"; } $end2 = microtime(true); $time2 = ($end2 - $start2); echo 'A difference of: '.($time2 - $time1) . ' seconds'; #=> A difference of approx: 0.244801044464 seconds;
A whopping 0.24 seconds over 1000000 string concatenations (a difference of about 0.00000024 per concatenation). I wouldn’t bother with this one, if the code is full of double quotes leave it.
Now, I am not suggesting that you rethink the micro optimizations that you make go ahead, make them if you must. But before you put too much thought into it, make those macro-optimizations that you are avoiding and clean up your code. Future you will thank you, especially if current you avoids dumb “micro-optimizations” like bit shifting rather than multiplying and dividing (dumb because for the most part, modern compilers make this optimization already, or your processor does a table lookup rather than doing the actual calculation).
#this: 9 * 256; #is way more readable than: 9 << 8;