MediaWiki master
benchmarkTitleValue.php
Go to the documentation of this file.
1<?php
25
26// @codeCoverageIgnoreStart
27require_once __DIR__ . '/../includes/Benchmarker.php';
28// @codeCoverageIgnoreEnd
29
35class BenchmarkTitleValue extends Benchmarker {
36
40 private $titleFormatter;
44 private $titleParser;
45
49 private $dbKey = 'FooBar';
53 private $titleValue;
57 private $title;
58
62 private $toParse;
63
64 public function __construct() {
65 parent::__construct();
66 $this->addDescription( 'Benchmark TitleValue vs Title.' );
67 }
68
69 public function execute() {
70 $this->titleFormatter = $this->getServiceContainer()->getTitleFormatter();
71 $this->titleParser = $this->getServiceContainer()->getTitleParser();
72 $this->titleValue = $this->constructTitleValue();
73 $this->title = $this->constructTitle();
74 $this->toParse = 'Category:FooBar';
75 $this->bench( [
76 [
77 'function' => [ $this, 'constructTitleValue' ],
78 ],
79 [
80 'function' => [ $this, 'constructTitle' ],
81 ],
82 [
83 'function' => [ $this, 'constructTitleSafe' ],
84 ],
85 [
86 'function' => [ $this, 'getPrefixedTextTitleValue' ],
87 ],
88 [
89 'function' => [ $this, 'getPrefixedTextTitle' ],
90 ],
91 'parseTitleValue cached' => [
92 'function' => [ $this, 'parseTitleValue' ],
93 'setup' => [ $this, 'randomize' ],
94 ],
95 'parseTitle cached' => [
96 'function' => [ $this, 'parseTitle' ],
97 'setup' => [ $this, 'randomize' ],
98 ],
99 'parseTitleValue no cache' => [
100 'function' => [ $this, 'parseTitleValue' ],
101 'setupEach' => [ $this, 'randomize' ],
102 ],
103 'parseTitle no cache' => [
104 'function' => [ $this, 'parseTitle' ],
105 'setupEach' => [ $this, 'randomize' ],
106 ],
107 ] );
108 }
109
113 protected function randomize() {
114 $this->dbKey = ucfirst( wfRandomString( 10 ) );
115 }
116
117 protected function constructTitleValue() {
118 return new TitleValue( NS_CATEGORY, $this->dbKey );
119 }
120
121 protected function constructTitle() {
122 return Title::makeTitle( NS_CATEGORY, $this->dbKey );
123 }
124
125 protected function constructTitleSafe() {
126 return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey );
127 }
128
129 protected function getPrefixedTextTitleValue() {
130 // This is really showing TitleFormatter aka MediaWikiTitleCodec perf
131 return $this->titleFormatter->getPrefixedText( $this->titleValue );
132 }
133
134 protected function getPrefixedTextTitle() {
135 return $this->title->getPrefixedText();
136 }
137
138 protected function parseTitleValue() {
139 // This is really showing TitleParser aka MediaWikiTitleCodec perf
140 $this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN );
141 }
142
143 protected function parseTitle() {
144 Title::newFromText( 'Category:' . $this->dbKey );
145 }
146}
147
148// @codeCoverageIgnoreStart
149$maintClass = BenchmarkTitleValue::class;
150require_once RUN_MAINTENANCE_IF_MAIN;
151// @codeCoverageIgnoreEnd
const NS_MAIN
Definition Defines.php:65
const NS_CATEGORY
Definition Defines.php:79
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Maintenance script that benchmarks TitleValue vs Title.
randomize()
Use a different dbKey each time to avoid influence of Title caches.
Represents the target of a wiki link.
Represents a title within MediaWiki.
Definition Title.php:78
A title formatter service for MediaWiki.
A title parser service for MediaWiki.