MediaWiki
1.34.0
bench_if_switch.php
Go to the documentation of this file.
1
<?php
27
require_once __DIR__ .
'/Benchmarker.php'
;
28
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
;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition:
Maintenance.php:39
BenchIfSwitch\doSwitch
doSwitch()
Definition:
bench_if_switch.php:71
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition:
Maintenance.php:348
BenchIfSwitch\execute
execute()
Do the actual work.
Definition:
bench_if_switch.php:40
Benchmarker\bench
bench(array $benchs)
Definition:
Benchmarker.php:50
BenchIfSwitch
Maintenance script that benchmark if elseif...
Definition:
bench_if_switch.php:34
BenchIfSwitch\doElseIf
doElseIf()
Definition:
bench_if_switch.php:48
BenchIfSwitch\__construct
__construct()
Default constructor.
Definition:
bench_if_switch.php:35
Benchmarker
Base class for benchmark scripts.
Definition:
Benchmarker.php:40
$maintClass
$maintClass
Definition:
bench_if_switch.php:109
maintenance
benchmarks
bench_if_switch.php
Generated on Thu Dec 19 2019 14:55:24 for MediaWiki by
1.8.16