MediaWiki REL1_32
bench_if_switch.php
Go to the documentation of this file.
1<?php
27require_once __DIR__ . '/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
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;
110require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that benchmark if elseif... versus switch case.
execute()
Do the actual work.
__construct()
Default constructor.
Base class for benchmark scripts.
bench(array $benchs)
addDescription( $text)
Set the description text.
require_once RUN_MAINTENANCE_IF_MAIN