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