MediaWiki REL1_35
bench_if_switch.php
Go to the documentation of this file.
1<?php
27require_once __DIR__ . '/../includes/Benchmarker.php';
28
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
51 protected function doElseIf() {
52 $a = 'z';
53 if ( $a == 'a' ) {
54 } elseif ( $a == 'b' ) {
55 } elseif ( $a == 'c' ) {
56 } elseif ( $a == 'd' ) {
57 } elseif ( $a == 'e' ) {
58 } elseif ( $a == 'f' ) {
59 } elseif ( $a == 'g' ) {
60 } elseif ( $a == 'h' ) {
61 } elseif ( $a == 'i' ) {
62 } elseif ( $a == 'j' ) {
63 } elseif ( $a == 'k' ) {
64 } elseif ( $a == 'l' ) {
65 } elseif ( $a == 'm' ) {
66 } elseif ( $a == 'n' ) {
67 } elseif ( $a == 'o' ) {
68 } elseif ( $a == 'p' ) {
69 } else {
70 }
71 }
72
76 protected function doSwitch() {
77 $a = 'z';
78 switch ( $a ) {
79 case 'b':
80 break;
81 case 'c':
82 break;
83 case 'd':
84 break;
85 case 'e':
86 break;
87 case 'f':
88 break;
89 case 'g':
90 break;
91 case 'h':
92 break;
93 case 'i':
94 break;
95 case 'j':
96 break;
97 case 'k':
98 break;
99 case 'l':
100 break;
101 case 'm':
102 break;
103 case 'n':
104 break;
105 case 'o':
106 break;
107 case 'p':
108 break;
109 default:
110 }
111 }
112}
113
114$maintClass = BenchIfSwitch::class;
115require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that benchmark if elseif... versus switch case.
execute()
Do the actual work.
doElseIf()
bench function 1 PhanSuspiciousValueComparison
__construct()
Default constructor.
doSwitch()
bench function 2
Base class for benchmark scripts.
bench(array $benchs)
addDescription( $text)
Set the description text.