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