MediaWiki
1.40.4
benchmarkTitleValue.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\MediaWikiServices
;
22
use
MediaWiki\Title\Title
;
23
24
require_once __DIR__ .
'/../includes/Benchmarker.php'
;
25
31
class
BenchmarkTitleValue
extends
Benchmarker
{
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;
145
require_once RUN_MAINTENANCE_IF_MAIN;
NS_MAIN
const NS_MAIN
Definition
Defines.php:64
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:78
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition
GlobalFunctions.php:264
$maintClass
$maintClass
Definition
benchmarkTitleValue.php:144
BenchmarkTitleValue
Maintenance script that benchmarks TitleValue vs Title.
Definition
benchmarkTitleValue.php:31
BenchmarkTitleValue\constructTitle
constructTitle()
Definition
benchmarkTitleValue.php:117
BenchmarkTitleValue\getPrefixedTextTitleValue
getPrefixedTextTitleValue()
Definition
benchmarkTitleValue.php:125
BenchmarkTitleValue\randomize
randomize()
Use a different dbKey each time to avoid influence of Title caches.
Definition
benchmarkTitleValue.php:109
BenchmarkTitleValue\parseTitle
parseTitle()
Definition
benchmarkTitleValue.php:139
BenchmarkTitleValue\parseTitleValue
parseTitleValue()
Definition
benchmarkTitleValue.php:134
BenchmarkTitleValue\__construct
__construct()
Default constructor.
Definition
benchmarkTitleValue.php:60
BenchmarkTitleValue\execute
execute()
Do the actual work.
Definition
benchmarkTitleValue.php:65
BenchmarkTitleValue\constructTitleSafe
constructTitleSafe()
Definition
benchmarkTitleValue.php:121
BenchmarkTitleValue\getPrefixedTextTitle
getPrefixedTextTitle()
Definition
benchmarkTitleValue.php:130
BenchmarkTitleValue\constructTitleValue
constructTitleValue()
Definition
benchmarkTitleValue.php:113
Benchmarker
Base class for benchmark scripts.
Definition
Benchmarker.php:40
Benchmarker\bench
bench(array $benchs)
Definition
Benchmarker.php:49
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:340
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:223
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:82
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition
TitleValue.php:40
TitleFormatter
A title formatter service for MediaWiki.
Definition
TitleFormatter.php:35
TitleParser
A title parser service for MediaWiki.
Definition
TitleParser.php:33
maintenance
benchmarks
benchmarkTitleValue.php
Generated on Thu Jun 27 2024 15:52:57 for MediaWiki by
1.10.0