Index: trunk/phase3/maintenance/benchmarks/bench_if_switch.php |
— | — | @@ -0,0 +1,88 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This come from r75429 message |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @file |
| 22 | + * @ingroup Maintenance |
| 23 | + * @author Platonides |
| 24 | + */ |
| 25 | + |
| 26 | +require_once( dirname( __FILE__ ) . '/Benchmarker.php' ); |
| 27 | +class bench_if_switch extends Benchmarker { |
| 28 | + |
| 29 | + public function __construct() { |
| 30 | + parent::__construct(); |
| 31 | + $this->mDescription = "Benchmark if elseif... versus switch case."; |
| 32 | + } |
| 33 | + |
| 34 | + public function execute() { |
| 35 | + $this->bench( array( |
| 36 | + array( 'function' => array( $this, 'doElseIf' ) ), |
| 37 | + array( 'function' => array( $this, 'doSwitch' ) ), |
| 38 | + )); |
| 39 | + print $this->getFormattedResults(); |
| 40 | + } |
| 41 | + |
| 42 | + // bench function 1 |
| 43 | + function doElseIf() { |
| 44 | + $a = 'z'; |
| 45 | + if( $a == 'a') {} |
| 46 | + elseif( $a == 'b') {} |
| 47 | + elseif( $a == 'c') {} |
| 48 | + elseif( $a == 'd') {} |
| 49 | + elseif( $a == 'e') {} |
| 50 | + elseif( $a == 'f') {} |
| 51 | + elseif( $a == 'g') {} |
| 52 | + elseif( $a == 'h') {} |
| 53 | + elseif( $a == 'i') {} |
| 54 | + elseif( $a == 'j') {} |
| 55 | + elseif( $a == 'k') {} |
| 56 | + elseif( $a == 'l') {} |
| 57 | + elseif( $a == 'm') {} |
| 58 | + elseif( $a == 'n') {} |
| 59 | + elseif( $a == 'o') {} |
| 60 | + elseif( $a == 'p') {} |
| 61 | + else {} |
| 62 | + } |
| 63 | + |
| 64 | + // bench function 2 |
| 65 | + function doSwitch() { |
| 66 | + $a = 'z'; |
| 67 | + switch( $a ) { |
| 68 | + case 'b': break; |
| 69 | + case 'c': break; |
| 70 | + case 'd': break; |
| 71 | + case 'e': break; |
| 72 | + case 'f': break; |
| 73 | + case 'g': break; |
| 74 | + case 'h': break; |
| 75 | + case 'i': break; |
| 76 | + case 'j': break; |
| 77 | + case 'k': break; |
| 78 | + case 'l': break; |
| 79 | + case 'm': break; |
| 80 | + case 'n': break; |
| 81 | + case 'o': break; |
| 82 | + case 'p': break; |
| 83 | + default: |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +$maintClass = 'bench_if_switch'; |
| 89 | +require_once( DO_MAINTENANCE ); |
Property changes on: trunk/phase3/maintenance/benchmarks/bench_if_switch.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 90 | + native |