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
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.