MediaWiki  1.30.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';
110 require_once RUN_MAINTENANCE_IF_MAIN;
BenchIfSwitch\doSwitch
doSwitch()
Definition: bench_if_switch.php:71
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
BenchIfSwitch\execute
execute()
Do the actual work.
Definition: bench_if_switch.php:40
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:46
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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:36
$maintClass
$maintClass
Definition: bench_if_switch.php:109