MediaWiki REL1_37
benchmarkCommentFormatter.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/../includes/Benchmarker.php';
4
6 public function __construct() {
7 parent::__construct();
8 $this->addDescription( 'Benchmark Linker::formatComment()' );
9 $this->addOption( 'file', 'A JSON API result from list=recentchanges',
10 false, true );
11 }
12
13 public function execute() {
14 $file = $this->getOption( 'file',
15 __DIR__ . '/data/CommentFormatter/rc100-2021-07-29.json' );
16 $json = file_get_contents( $file );
17 if ( !$json ) {
18 $this->fatalError( "Unable to read input file \"$file\"" );
19 }
20 $result = json_decode( $json, true );
21 if ( !isset( $result['query']['recentchanges'] ) ) {
22 $this->fatalError( "Invalid JSON data" );
23 }
24 $entries = $result['query']['recentchanges'];
25 $inputs = [];
26 foreach ( $entries as $entry ) {
27 $inputs[] = [
28 'comment' => $entry['comment'],
29 'title' => Title::newFromText( $entry['title'] )
30 ];
31 }
32 $this->bench( [
33 'Linker::formatComment' => [
34 'function' => static function () use ( $inputs ) {
35 Title::clearCaches();
36 foreach ( $inputs as $input ) {
38 $input['comment'],
39 $input['title']
40 );
41 }
42 },
43 ],
44 ] );
45 }
46}
47
48$maintClass = BenchmarkCommentFormatter::class;
49require_once RUN_MAINTENANCE_IF_MAIN;
Base class for benchmark scripts.
bench(array $benchs)
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition Linker.php:1372
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42