MediaWiki master
benchmarkTitleValue.php
Go to the documentation of this file.
1<?php
26
27// @codeCoverageIgnoreStart
28require_once __DIR__ . '/../includes/Benchmarker.php';
29// @codeCoverageIgnoreEnd
30
37
41 private $titleFormatter;
45 private $titleParser;
46
50 private $dbKey = 'FooBar';
54 private $titleValue;
58 private $title;
59
63 private $toParse;
64
65 public function __construct() {
66 parent::__construct();
67 $this->addDescription( 'Benchmark TitleValue vs Title.' );
68 }
69
70 public function execute() {
71 $this->titleFormatter = $this->getServiceContainer()->getTitleFormatter();
72 $this->titleParser = $this->getServiceContainer()->getTitleParser();
73 $this->titleValue = $this->constructTitleValue();
74 $this->title = $this->constructTitle();
75 $this->toParse = 'Category:FooBar';
76 $this->bench( [
77 [
78 'function' => [ $this, 'constructTitleValue' ],
79 ],
80 [
81 'function' => [ $this, 'constructTitle' ],
82 ],
83 [
84 'function' => [ $this, 'constructTitleSafe' ],
85 ],
86 [
87 'function' => [ $this, 'getPrefixedTextTitleValue' ],
88 ],
89 [
90 'function' => [ $this, 'getPrefixedTextTitle' ],
91 ],
92 'parseTitleValue cached' => [
93 'function' => [ $this, 'parseTitleValue' ],
94 'setup' => [ $this, 'randomize' ],
95 ],
96 'parseTitle cached' => [
97 'function' => [ $this, 'parseTitle' ],
98 'setup' => [ $this, 'randomize' ],
99 ],
100 'parseTitleValue no cache' => [
101 'function' => [ $this, 'parseTitleValue' ],
102 'setupEach' => [ $this, 'randomize' ],
103 ],
104 'parseTitle no cache' => [
105 'function' => [ $this, 'parseTitle' ],
106 'setupEach' => [ $this, 'randomize' ],
107 ],
108 ] );
109 }
110
114 protected function randomize() {
115 $this->dbKey = ucfirst( wfRandomString( 10 ) );
116 }
117
118 protected function constructTitleValue() {
119 return new TitleValue( NS_CATEGORY, $this->dbKey );
120 }
121
122 protected function constructTitle() {
123 return Title::makeTitle( NS_CATEGORY, $this->dbKey );
124 }
125
126 protected function constructTitleSafe() {
127 return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey );
128 }
129
130 protected function getPrefixedTextTitleValue() {
131 // This is really showing TitleFormatter perf
132 return $this->titleFormatter->getPrefixedText( $this->titleValue );
133 }
134
135 protected function getPrefixedTextTitle() {
136 return $this->title->getPrefixedText();
137 }
138
139 protected function parseTitleValue() {
140 // This is really showing TitleParser perf
141 $this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN );
142 }
143
144 protected function parseTitle() {
145 Title::newFromText( 'Category:' . $this->dbKey );
146 }
147}
148
149// @codeCoverageIgnoreStart
150$maintClass = BenchmarkTitleValue::class;
151require_once RUN_MAINTENANCE_IF_MAIN;
152// @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.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
A title formatter service for MediaWiki.
A title parser service for MediaWiki.
Represents the target of a wiki link.
Represents a title within MediaWiki.
Definition Title.php:78