Merge "Add benchmark for Linker::formatComment() in preparation for refactor"

This commit is contained in:
jenkins-bot 2021-08-26 03:24:38 +00:00 committed by Gerrit Code Review
commit c818f29a4c
8 changed files with 57 additions and 2 deletions

View file

@ -11,6 +11,7 @@
/vendor/
/tests/coverage/
/tests/phpunit/data/registration/duplicate_keys.json
/maintenance/benchmarks/data/
# Nested projects
/extensions/

View file

@ -187,6 +187,7 @@ $wgAutoloadLocalClasses = [
'BatchRowWriter' => __DIR__ . '/includes/utils/BatchRowWriter.php',
'BcryptPassword' => __DIR__ . '/includes/password/BcryptPassword.php',
'BenchUtf8TitleCheck' => __DIR__ . '/maintenance/benchmarks/bench_utf8_title_check.php',
'BenchmarkCommentFormatter' => __DIR__ . '/maintenance/benchmarks/benchmarkCommentFormatter.php',
'BenchmarkEval' => __DIR__ . '/maintenance/benchmarks/benchmarkEval.php',
'BenchmarkHooks' => __DIR__ . '/maintenance/benchmarks/benchmarkHooks.php',
'BenchmarkJSMinPlus' => __DIR__ . '/maintenance/benchmarks/benchmarkJSMinPlus.php',

View file

@ -11,5 +11,7 @@ For example:
## Fixtures
* tidy/australia-untidy.html.gz: Representative input text for benchmarkTidy.php.
* data/tidy/australia-untidy.html.gz: Representative input text for benchmarkTidy.php.
It needs to be decompressed before use.
* data/CommentFormatter/rc100-2021-07-29.json: Input for Linker::formatComment() from
https://en.wikipedia.org/w/api.php?action=query&format=json&list=recentchanges&rcprop=title%7Ccomment&rclimit=100

View file

@ -0,0 +1,50 @@
<?php
require_once __DIR__ . '/../includes/Benchmarker.php';
class BenchmarkCommentFormatter extends Benchmarker {
public function __construct() {
parent::__construct();
$this->addDescription( 'Benchmark Linker::formatComment()' );
$this->addOption( 'file', 'A JSON API result from list=recentchanges',
false, true );
}
public function execute() {
$file = $this->getOption( 'file',
__DIR__ . '/data/CommentFormatter/rc100-2021-07-29.json' );
$json = file_get_contents( $file );
if ( !$json ) {
$this->fatalError( "Unable to read input file \"$file\"" );
}
$result = json_decode( $json, true );
if ( !isset( $result['query']['recentchanges'] ) ) {
$this->fatalError( "Invalid JSON data" );
throw new \Exception( 'Invalid JSON data' ); // for phan
}
$entries = $result['query']['recentchanges'];
$inputs = [];
foreach ( $entries as $entry ) {
$inputs[] = [
'comment' => $entry['comment'],
'title' => Title::newFromText( $entry['title'] )
];
}
$this->bench( [
'Linker::formatComment' => [
'function' => static function () use ( $inputs ) {
Title::clearCaches();
foreach ( $inputs as $input ) {
Linker::formatComment(
$input['comment'],
$input['title']
);
}
},
],
] );
}
}
$maintClass = BenchmarkCommentFormatter::class;
require_once RUN_MAINTENANCE_IF_MAIN;

View file

@ -30,7 +30,7 @@ class BenchmarkTidy extends Benchmarker {
}
public function execute() {
$file = $this->getOption( 'file', __DIR__ . '/tidy/australia-untidy.html.gz' );
$file = $this->getOption( 'file', __DIR__ . '/data/tidy/australia-untidy.html.gz' );
$html = $this->loadFile( $file );
if ( $html === false ) {
$this->fatalError( "Unable to open input file" );

File diff suppressed because one or more lines are too long