PHP Benchmarking: Loops
A little more on PHP Benchmarking, I was reading a bit about it over the weekend. Some sites were also claiming that you can optimize your loops by using do and while loops instead of for loops.
Here are my results for those, I had to bump it up to 2,000,000 loops to see a noticeable difference.
Results:
While Loop: 0.37 secs
Do-While Loop: 0.37 secs
Tests:
for ($i=0; $i < 2000000; $i++) { }
while ($i < 2000000) { ++$i; }
do { ++$i; } while ($i < 2000000);
The performance difference is probably not enough to notice even on a real heavily loaded server, not really worth the time to change your code. Spend your time making big changes: use a cache and optimizer, improve site architecture and other changes will have a much larger impact. Here’s a great article on PHP optimization talking about bigger pieces to look at.
Technorati Tags: php, benchmarking






