(I APOLOGIZE IF YOU RECEIVE THIS MESSAGE TWICE. MY HOST IS HAVING ISSUES.) My first thought was either the compiler would optimize any difference away or the switch might be fastest. However, I've always wondered about this myself so I built a test using code I found at http://drupal.org/node/110128 . I added an "else if" test and an outer loop, and broke out the end time call. The text is here: http://pokemywaffle.com/test/bench.txt
First of all, there are issues with using microtime to try and benchmark things, but for now we'll ignore it. This is for funsies. :) Second of all, I ran this on a box with nothing else running on it at the time. Typical results follow: else if: 2.88 elseif: 2.86 switch: 2.99 else if: 2.85 elseif: 2.87 switch: 2.92 else if: 2.81 elseif: 2.88 switch: 2.96 else if: 2.87 elseif: 2.86 switch: 2.97 else if: 2.87 elseif: 2.90 switch: 2.98 I ran it a bunch of times, with higher loop values and whatnot. else if is often the fastest, and switch is often the slowest. But overall the differences are inconclusive and pretty marginal. How often are you going to be doing two million conditionals in one page anyway? _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
