MediaWiki 1.40.4
benchmarkTitleValue.php
Go to the documentation of this file.
1<?php
23
24require_once __DIR__ . '/../includes/Benchmarker.php';
25
32
36 private $titleFormatter;
40 private $titleParser;
41
45 private $dbKey = 'FooBar';
49 private $titleValue;
53 private $title;
54
58 private $toParse;
59
60 public function __construct() {
61 parent::__construct();
62 $this->addDescription( 'Benchmark TitleValue vs Title.' );
63 }
64
65 public function execute() {
66 $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
67 $this->titleParser = MediaWikiServices::getInstance()->getTitleParser();
68 $this->titleValue = $this->constructTitleValue();
69 $this->title = $this->constructTitle();
70 $this->toParse = 'Category:FooBar';
71 $this->bench( [
72 [
73 'function' => [ $this, 'constructTitleValue' ],
74 ],
75 [
76 'function' => [ $this, 'constructTitle' ],
77 ],
78 [
79 'function' => [ $this, 'constructTitleSafe' ],
80 ],
81 [
82 'function' => [ $this, 'getPrefixedTextTitleValue' ],
83 ],
84 [
85 'function' => [ $this, 'getPrefixedTextTitle' ],
86 ],
87 'parseTitleValue cached' => [
88 'function' => [ $this, 'parseTitleValue' ],
89 'setup' => [ $this, 'randomize' ],
90 ],
91 'parseTitle cached' => [
92 'function' => [ $this, 'parseTitle' ],
93 'setup' => [ $this, 'randomize' ],
94 ],
95 'parseTitleValue no cache' => [
96 'function' => [ $this, 'parseTitleValue' ],
97 'setupEach' => [ $this, 'randomize' ],
98 ],
99 'parseTitle no cache' => [
100 'function' => [ $this, 'parseTitle' ],
101 'setupEach' => [ $this, 'randomize' ],
102 ],
103 ] );
104 }
105
109 protected function randomize() {
110 $this->dbKey = ucfirst( wfRandomString( 10 ) );
111 }
112
113 protected function constructTitleValue() {
114 return new TitleValue( NS_CATEGORY, $this->dbKey );
115 }
116
117 protected function constructTitle() {
118 return Title::makeTitle( NS_CATEGORY, $this->dbKey );
119 }
120
121 protected function constructTitleSafe() {
122 return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey );
123 }
124
125 protected function getPrefixedTextTitleValue() {
126 // This is really showing TitleFormatter aka MediaWikiTitleCodec perf
127 return $this->titleFormatter->getPrefixedText( $this->titleValue );
128 }
129
130 protected function getPrefixedTextTitle() {
131 return $this->title->getPrefixedText();
132 }
133
134 protected function parseTitleValue() {
135 // This is really showing TitleParser aka MediaWikiTitleCodec perf
136 $this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN );
137 }
138
139 protected function parseTitle() {
140 Title::newFromText( 'Category:' . $this->dbKey );
141 }
142}
143
144$maintClass = BenchmarkTitleValue::class;
145require_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)
addDescription( $text)
Set the description text.
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:82
Represents a page (or page fragment) title within MediaWiki.
A title formatter service for MediaWiki.
A title parser service for MediaWiki.