PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I was really surprised with this result.
I thought that with this code after the second elseif statement the rest of the elseif statements don't have to be evaluated and therefore faster that the second script.
But this is not the case.
Can someone explain why the second script is faster?
I was one again forgotten to disable the eAccelerator.
With eAccelerator disabled the execution time is the other way around.
I also have made a comparison with switch.
You can see that elseif and switch are not to different,
if statements are now much slower.
q = 2; q = 9;
------------------------------------------------
switch 870 ms 1370 ms
switch + break 765 ms 1400 ms
elseif 885 ms 875 ms
if 2325 ms 2390 ms
Update: here are the results with eAccelerator enabled.
eAccelerator q = 2; q = 9;
------------------------------------------------
switch 700 ms 1110 ms
switch + break 695 ms 1110 ms
elseif 805 ms 1700 ms
if 340 ms 345 ms
Well, my first reaction was "then your eAcceleraor sucks!" (causing my switch to be slow... pssh! ) until I realized that, with it, everything is faster. Although, I'd never think that an accelerator would work backwards like that and make you have to change your coding style for maximum efficiency.