MediaWiki  1.33.0
benchmarkTitleValue.php
Go to the documentation of this file.
1 <?php
22 
23 require_once __DIR__ . '/Benchmarker.php';
24 
31 
35  private $titleFormatter;
39  private $titleParser;
40 
44  private $dbKey = 'FooBar';
48  private $titleValue;
52  private $title;
53 
57  private $toParse;
58 
59  public function __construct() {
60  parent::__construct();
61  $this->addDescription( 'Benchmark TitleValue vs Title.' );
62  }
63 
64  public function execute() {
65  $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
66  $this->titleParser = MediaWikiServices::getInstance()->getTitleParser();
67  $this->titleValue = $this->constructTitleValue();
68  $this->title = $this->constructTitle();
69  $this->toParse = 'Category:FooBar';
70  $this->bench( [
71  [
72  'function' => [ $this, 'constructTitleValue' ],
73  ],
74  [
75  'function' => [ $this, 'constructTitle' ],
76  ],
77  [
78  'function' => [ $this, 'constructTitleSafe' ],
79  ],
80  [
81  'function' => [ $this, 'getPrefixedTextTitleValue' ],
82  ],
83  [
84  'function' => [ $this, 'getPrefixedTextTitle' ],
85  ],
86  'parseTitleValue cached' => [
87  'function' => [ $this, 'parseTitleValue' ],
88  'setup' => [ $this, 'randomize' ],
89  ],
90  'parseTitle cached' => [
91  'function' => [ $this, 'parseTitle' ],
92  'setup' => [ $this, 'randomize' ],
93  ],
94  'parseTitleValue no cache' => [
95  'function' => [ $this, 'parseTitleValue' ],
96  'setupEach' => [ $this, 'randomize' ],
97  ],
98  'parseTitle no cache' => [
99  'function' => [ $this, 'parseTitle' ],
100  'setupEach' => [ $this, 'randomize' ],
101  ],
102  ] );
103  }
104 
108  protected function randomize() {
109  $this->dbKey = ucfirst( wfRandomString( 10 ) );
110  }
111 
112  protected function constructTitleValue() {
113  return new TitleValue( NS_CATEGORY, $this->dbKey );
114  }
115 
116  protected function constructTitle() {
117  return Title::makeTitle( NS_CATEGORY, $this->dbKey );
118  }
119 
120  protected function constructTitleSafe() {
121  return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey );
122  }
123 
124  protected function getPrefixedTextTitleValue() {
125  // This is really showing TitleFormatter aka MediaWikiTitleCodec perf
126  return $this->titleFormatter->getPrefixedText( $this->titleValue );
127  }
128 
129  protected function getPrefixedTextTitle() {
130  return $this->title->getPrefixedText();
131  }
132 
133  protected function parseTitleValue() {
134  // This is really showing TitleParser aka MediaWikiTitleCodec perf
135  $this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN );
136  }
137 
138  protected function parseTitle() {
139  Title::newFromText( 'Category:' . $this->dbKey );
140  }
141 }
142 
144 require_once RUN_MAINTENANCE_IF_MAIN;
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
BenchmarkTitleValue
Maintenance script that benchmarks TitleValue vs Title.
Definition: benchmarkTitleValue.php:30
BenchmarkTitleValue\getPrefixedTextTitleValue
getPrefixedTextTitleValue()
Definition: benchmarkTitleValue.php:124
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
BenchmarkTitleValue\$toParse
string $toParse
Definition: benchmarkTitleValue.php:57
BenchmarkTitleValue\$titleFormatter
TitleFormatter $titleFormatter
Definition: benchmarkTitleValue.php:35
BenchmarkTitleValue\randomize
randomize()
Use a different dbKey each time to avoid influence of Title caches.
Definition: benchmarkTitleValue.php:108
BenchmarkTitleValue\$dbKey
string $dbKey
Definition: benchmarkTitleValue.php:44
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:50
BenchmarkTitleValue\$title
Title $title
Definition: benchmarkTitleValue.php:52
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
BenchmarkTitleValue\parseTitleValue
parseTitleValue()
Definition: benchmarkTitleValue.php:133
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
BenchmarkTitleValue\parseTitle
parseTitle()
Definition: benchmarkTitleValue.php:138
BenchmarkTitleValue\getPrefixedTextTitle
getPrefixedTextTitle()
Definition: benchmarkTitleValue.php:129
BenchmarkTitleValue\__construct
__construct()
Default constructor.
Definition: benchmarkTitleValue.php:59
BenchmarkTitleValue\$titleParser
TitleParser $titleParser
Definition: benchmarkTitleValue.php:39
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
TitleParser
A title parser service for MediaWiki.
Definition: TitleParser.php:33
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:604
BenchmarkTitleValue\execute
execute()
Do the actual work.
Definition: benchmarkTitleValue.php:64
title
title
Definition: parserTests.txt:245
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
Title
Represents a title within MediaWiki.
Definition: Title.php:40
$maintClass
$maintClass
Definition: benchmarkTitleValue.php:143
TitleFormatter
A title formatter service for MediaWiki.
Definition: TitleFormatter.php:34
BenchmarkTitleValue\constructTitle
constructTitle()
Definition: benchmarkTitleValue.php:116
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
BenchmarkTitleValue\$titleValue
TitleValue $titleValue
Definition: benchmarkTitleValue.php:48
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
BenchmarkTitleValue\constructTitleSafe
constructTitleSafe()
Definition: benchmarkTitleValue.php:120
BenchmarkTitleValue\constructTitleValue
constructTitleValue()
Definition: benchmarkTitleValue.php:112
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:298