Reputation: 5012
For Benchmarking PHP with iterations, I have considered a large for loop
for($j=0;$j<20000000;$j++)
;
Executing the same takes around 2.5 seconds in PHP 5.4 with eAccelerator enabled
The same loop in .jsp file takes around 15 milliseconds
for(int j=0;j<20000000;j++)
;
Why is there such a huge difference between both of them? Is there a way to make it work faster in PHP
Upvotes: 0
Views: 167
Reputation: 46040
These types of micro benchmarks should be of no concern.
Anyway this loop is slightly faster:
$i = 20000000;
while($i--);
http://benchmarksgame.alioth.debian.org/u32/compare.php?lang=java&lang2=php
Upvotes: 0
Reputation: 66681
At 15ms the loop was probably optimized by the JIT. Unless you're using the HipHop VM, your PHP loop doesn't really stand a chance.
Keep in mind that the performance of a tight loop is hardly representative of relative performance in the real world with real workloads. Check out The Computer Language Benchmarks Game instead -- and even their far more meaningful measurements are to be taken with a grain of salt.
Upvotes: 4