MediaWiki master
benchmarkTitleValue.php
Go to the documentation of this file.
1<?php
25
26require_once __DIR__ . '/../includes/Benchmarker.php';
27
34
38 private $titleFormatter;
42 private $titleParser;
43
47 private $dbKey = 'FooBar';
51 private $titleValue;
55 private $title;
56
60 private $toParse;
61
62 public function __construct() {
63 parent::__construct();
64 $this->addDescription( 'Benchmark TitleValue vs Title.' );
65 }
66
67 public function execute() {
68 $this->titleFormatter = $this->getServiceContainer()->getTitleFormatter();
69 $this->titleParser = $this->getServiceContainer()->getTitleParser();
70 $this->titleValue = $this->constructTitleValue();
71 $this->title = $this->constructTitle();
72 $this->toParse = 'Category:FooBar';
73 $this->bench( [
74 [
75 'function' => [ $this, 'constructTitleValue' ],
76 ],
77 [
78 'function' => [ $this, 'constructTitle' ],
79 ],
80 [
81 'function' => [ $this, 'constructTitleSafe' ],
82 ],
83 [
84 'function' => [ $this, 'getPrefixedTextTitleValue' ],
85 ],
86 [
87 'function' => [ $this, 'getPrefixedTextTitle' ],
88 ],
89 'parseTitleValue cached' => [
90 'function' => [ $this, 'parseTitleValue' ],
91 'setup' => [ $this, 'randomize' ],
92 ],
93 'parseTitle cached' => [
94 'function' => [ $this, 'parseTitle' ],
95 'setup' => [ $this, 'randomize' ],
96 ],
97 'parseTitleValue no cache' => [
98 'function' => [ $this, 'parseTitleValue' ],
99 'setupEach' => [ $this, 'randomize' ],
100 ],
101 'parseTitle no cache' => [
102 'function' => [ $this, 'parseTitle' ],
103 'setupEach' => [ $this, 'randomize' ],
104 ],
105 ] );
106 }
107
111 protected function randomize() {
112 $this->dbKey = ucfirst( wfRandomString( 10 ) );
113 }
114
115 protected function constructTitleValue() {
116 return new TitleValue( NS_CATEGORY, $this->dbKey );
117 }
118
119 protected function constructTitle() {
120 return Title::makeTitle( NS_CATEGORY, $this->dbKey );
121 }
122
123 protected function constructTitleSafe() {
124 return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey );
125 }
126
127 protected function getPrefixedTextTitleValue() {
128 // This is really showing TitleFormatter aka MediaWikiTitleCodec perf
129 return $this->titleFormatter->getPrefixedText( $this->titleValue );
130 }
131
132 protected function getPrefixedTextTitle() {
133 return $this->title->getPrefixedText();
134 }
135
136 protected function parseTitleValue() {
137 // This is really showing TitleParser aka MediaWikiTitleCodec perf
138 $this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN );
139 }
140
141 protected function parseTitle() {
142 Title::newFromText( 'Category:' . $this->dbKey );
143 }
144}
145
146$maintClass = BenchmarkTitleValue::class;
147require_once RUN_MAINTENANCE_IF_MAIN;
const NS_MAIN
Definition Defines.php:64
const NS_CATEGORY
Definition Defines.php:78
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.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
bench(array $benchs)
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
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.