| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Title\Title; |
| 22 |
use MediaWiki\Title\TitleFormatter; |
| 23 |
use MediaWiki\Title\TitleParser; |
| 24 |
use MediaWiki\Title\TitleValue; |
| 25 |
|
| 26 |
|
| 27 |
require_once __DIR__ . '/../includes/Benchmarker.php'; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class BenchmarkTitleValue extends Benchmarker { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
private $titleFormatter; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
private $titleParser; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
private $dbKey = 'FooBar'; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
private $titleValue; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
private $title; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
private $toParse; |
| 63 |
|
| 64 |
public function __construct() { |
| 65 |
parent::__construct(); |
| 66 |
$this->addDescription( 'Benchmark TitleValue vs Title.' ); |
| 67 |
} |
| 68 |
|
| 69 |
public function execute() { |
| 70 |
$this->titleFormatter = $this->getServiceContainer()->getTitleFormatter(); |
| 71 |
$this->titleParser = $this->getServiceContainer()->getTitleParser(); |
| 72 |
$this->titleValue = $this->constructTitleValue(); |
| 73 |
$this->title = $this->constructTitle(); |
| 74 |
$this->toParse = 'Category:FooBar'; |
| 75 |
$this->bench( [ |
| 76 |
[ |
| 77 |
'function' => [ $this, 'constructTitleValue' ], |
| 78 |
], |
| 79 |
[ |
| 80 |
'function' => [ $this, 'constructTitle' ], |
| 81 |
], |
| 82 |
[ |
| 83 |
'function' => [ $this, 'constructTitleSafe' ], |
| 84 |
], |
| 85 |
[ |
| 86 |
'function' => [ $this, 'getPrefixedTextTitleValue' ], |
| 87 |
], |
| 88 |
[ |
| 89 |
'function' => [ $this, 'getPrefixedTextTitle' ], |
| 90 |
], |
| 91 |
'parseTitleValue cached' => [ |
| 92 |
'function' => [ $this, 'parseTitleValue' ], |
| 93 |
'setup' => [ $this, 'randomize' ], |
| 94 |
], |
| 95 |
'parseTitle cached' => [ |
| 96 |
'function' => [ $this, 'parseTitle' ], |
| 97 |
'setup' => [ $this, 'randomize' ], |
| 98 |
], |
| 99 |
'parseTitleValue no cache' => [ |
| 100 |
'function' => [ $this, 'parseTitleValue' ], |
| 101 |
'setupEach' => [ $this, 'randomize' ], |
| 102 |
], |
| 103 |
'parseTitle no cache' => [ |
| 104 |
'function' => [ $this, 'parseTitle' ], |
| 105 |
'setupEach' => [ $this, 'randomize' ], |
| 106 |
], |
| 107 |
] ); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
protected function randomize() { |
| 114 |
$this->dbKey = ucfirst( wfRandomString( 10 ) ); |
| 115 |
} |
| 116 |
|
| 117 |
protected function constructTitleValue() { |
| 118 |
return new TitleValue( NS_CATEGORY, $this->dbKey ); |
| 119 |
} |
| 120 |
|
| 121 |
protected function constructTitle() { |
| 122 |
return Title::makeTitle( NS_CATEGORY, $this->dbKey ); |
| 123 |
} |
| 124 |
|
| 125 |
protected function constructTitleSafe() { |
| 126 |
return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey ); |
| 127 |
} |
| 128 |
|
| 129 |
protected function getPrefixedTextTitleValue() { |
| 130 |
|
| 131 |
return $this->titleFormatter->getPrefixedText( $this->titleValue ); |
| 132 |
} |
| 133 |
|
| 134 |
protected function getPrefixedTextTitle() { |
| 135 |
return $this->title->getPrefixedText(); |
| 136 |
} |
| 137 |
|
| 138 |
protected function parseTitleValue() { |
| 139 |
|
| 140 |
$this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN ); |
| 141 |
} |
| 142 |
|
| 143 |
protected function parseTitle() { |
| 144 |
Title::newFromText( 'Category:' . $this->dbKey ); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
$maintClass = BenchmarkTitleValue::class; |
| 150 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 151 |
|