rendered paste body<?php/** * Results on my box running within ZDE: * X-Powered-By: PHP/5.2.0 * Content-type: text/html * * case_attempt: 8.367699 * short_if: 3.450575 * open_if: 4.021634 * closed_if: 4.627933 * * There appears to be little optimization within the php interpreter itself and shortif's are the fastest. */ $_GLOBALS["X"]=array(1,2,3,0); function o($n){ return $_GLOBALS["X"][$n]; } function case_attempt($n){ switch($n){ case 0:return 1; case 1:return 2; case 2:return 3; default:return 0; } } function short_if($n){ return 0==$n?1:(1==$n?2:(2==$n?3:0)); } function open_if($n){ if(0==$n)return 1; else if(1==$n)return 2; else if(2==$n)return 3; else return 0; } function closed_if($n){ if(0==$n){ return 1; } elseif(1==$n){ return 2; } elseif(2==$n){ return 3; } else { return 0; } } function t($func){ $start=microtime(1); for($i=0;$i<5e5;$i++) $func($i%6); printf("\n%10s: %f",$func,microtime(1)-$start); } t("case_attempt"); t("short_if"); t("open_if"); t("closed_if");?>