Merge "Fix sessionfailure i18n message during authentication"
[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 BenchIfSwitch extends Benchmarker {
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription( 'Benchmark if elseif... versus switch case.' );
38 }
39
40 public function execute() {
41 $this->bench( [
42 [ 'function' => [ $this, 'doElseIf' ] ],
43 [ 'function' => [ $this, 'doSwitch' ] ],
44 ] );
45 }
46
47 // bench function 1
48 protected function doElseIf() {
49 $a = 'z';
50 if ( $a == 'a' ) {
51 } elseif ( $a == 'b' ) {
52 } elseif ( $a == 'c' ) {
53 } elseif ( $a == 'd' ) {
54 } elseif ( $a == 'e' ) {
55 } elseif ( $a == 'f' ) {
56 } elseif ( $a == 'g' ) {
57 } elseif ( $a == 'h' ) {
58 } elseif ( $a == 'i' ) {
59 } elseif ( $a == 'j' ) {
60 } elseif ( $a == 'k' ) {
61 } elseif ( $a == 'l' ) {
62 } elseif ( $a == 'm' ) {
63 } elseif ( $a == 'n' ) {
64 } elseif ( $a == 'o' ) {
65 } elseif ( $a == 'p' ) {
66 } else {
67 }
68 }
69
70 // bench function 2
71 protected function doSwitch() {
72 $a = 'z';
73 switch ( $a ) {
74 case 'b':
75 break;
76 case 'c':
77 break;
78 case 'd':
79 break;
80 case 'e':
81 break;
82 case 'f':
83 break;
84 case 'g':
85 break;
86 case 'h':
87 break;
88 case 'i':
89 break;
90 case 'j':
91 break;
92 case 'k':
93 break;
94 case 'l':
95 break;
96 case 'm':
97 break;
98 case 'n':
99 break;
100 case 'o':
101 break;
102 case 'p':
103 break;
104 default:
105 }
106 }
107 }
108
109 $maintClass = BenchIfSwitch::class;
110 require_once RUN_MAINTENANCE_IF_MAIN;