MediaWiki
REL1_41
benchmarkTitleValue.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\Title\Title
;
22
use
MediaWiki\Title\TitleFormatter
;
23
use
MediaWiki\Title\TitleParser
;
24
use
MediaWiki\Title\TitleValue
;
25
26
require_once __DIR__ .
'/../includes/Benchmarker.php'
;
27
33
class
BenchmarkTitleValue
extends
Benchmarker
{
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;
147
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:267
$maintClass
$maintClass
Definition
benchmarkTitleValue.php:146
BenchmarkTitleValue
Maintenance script that benchmarks TitleValue vs Title.
Definition
benchmarkTitleValue.php:33
BenchmarkTitleValue\constructTitle
constructTitle()
Definition
benchmarkTitleValue.php:119
BenchmarkTitleValue\getPrefixedTextTitleValue
getPrefixedTextTitleValue()
Definition
benchmarkTitleValue.php:127
BenchmarkTitleValue\randomize
randomize()
Use a different dbKey each time to avoid influence of Title caches.
Definition
benchmarkTitleValue.php:111
BenchmarkTitleValue\parseTitle
parseTitle()
Definition
benchmarkTitleValue.php:141
BenchmarkTitleValue\parseTitleValue
parseTitleValue()
Definition
benchmarkTitleValue.php:136
BenchmarkTitleValue\__construct
__construct()
Default constructor.
Definition
benchmarkTitleValue.php:62
BenchmarkTitleValue\execute
execute()
Do the actual work.
Definition
benchmarkTitleValue.php:67
BenchmarkTitleValue\constructTitleSafe
constructTitleSafe()
Definition
benchmarkTitleValue.php:123
BenchmarkTitleValue\getPrefixedTextTitle
getPrefixedTextTitle()
Definition
benchmarkTitleValue.php:132
BenchmarkTitleValue\constructTitleValue
constructTitleValue()
Definition
benchmarkTitleValue.php:115
Benchmarker
Base class for benchmark scripts.
Definition
Benchmarker.php:40
Benchmarker\bench
bench(array $benchs)
Definition
Benchmarker.php:49
Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:637
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:325
MediaWiki\Title\TitleValue
Represents the target of a wiki link.
Definition
TitleValue.php:44
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:76
MediaWiki\Title\TitleFormatter
A title formatter service for MediaWiki.
Definition
TitleFormatter.php:39
MediaWiki\Title\TitleParser
A title parser service for MediaWiki.
Definition
TitleParser.php:35
maintenance
benchmarks
benchmarkTitleValue.php
Generated on Wed Nov 27 2024 06:26:09 for MediaWiki by
1.10.0