MediaWiki  REL1_19
bench_if_switch.php
Go to the documentation of this file.
00001 <?php
00025 require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
00026 class bench_if_switch extends Benchmarker {
00027 
00028         public function __construct() {
00029                 parent::__construct();
00030                 $this->mDescription = "Benchmark if elseif... versus switch case.";
00031         }
00032 
00033         public function execute() {
00034                 $this->bench( array(
00035                         array( 'function' => array( $this, 'doElseIf' ) ),
00036                         array( 'function' => array( $this, 'doSwitch' ) ),
00037                 ));
00038                 print $this->getFormattedResults();
00039         }
00040 
00041         // bench function 1
00042         function doElseIf() {
00043                 $a = 'z';
00044                 if( $a == 'a') {}
00045                 elseif( $a == 'b') {}
00046                 elseif( $a == 'c') {}
00047                 elseif( $a == 'd') {}
00048                 elseif( $a == 'e') {}
00049                 elseif( $a == 'f') {}
00050                 elseif( $a == 'g') {}
00051                 elseif( $a == 'h') {}
00052                 elseif( $a == 'i') {}
00053                 elseif( $a == 'j') {}
00054                 elseif( $a == 'k') {}
00055                 elseif( $a == 'l') {}
00056                 elseif( $a == 'm') {}
00057                 elseif( $a == 'n') {}
00058                 elseif( $a == 'o') {}
00059                 elseif( $a == 'p') {}
00060                 else {}
00061         }
00062 
00063         // bench function 2
00064         function doSwitch() {
00065                 $a = 'z';
00066                 switch( $a ) {
00067                         case 'b': break;
00068                         case 'c': break;
00069                         case 'd': break;
00070                         case 'e': break;
00071                         case 'f': break;
00072                         case 'g': break;
00073                         case 'h': break;
00074                         case 'i': break;
00075                         case 'j': break;
00076                         case 'k': break;
00077                         case 'l': break;
00078                         case 'm': break;
00079                         case 'n': break;
00080                         case 'o': break;
00081                         case 'p': break;
00082                         default:
00083                 }
00084         }
00085 }
00086 
00087 $maintClass = 'bench_if_switch';
00088 require_once( RUN_MAINTENANCE_IF_MAIN );