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