X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fbenchmarks%2FbenchmarkTidy.php;h=e9a30f9b1f42381ddabdb4888a76edd1e986f48c;hb=bccbafd6d857224a495d113d40bc7b7d7139f4e9;hp=14791745fe17a5abe141d8b5c1986fd5876009ad;hpb=ca55cfd87d2efc41b6ab208d60d1cde61f0ac9c0;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/benchmarks/benchmarkTidy.php b/maintenance/benchmarks/benchmarkTidy.php index 14791745fe..e9a30f9b1f 100644 --- a/maintenance/benchmarks/benchmarkTidy.php +++ b/maintenance/benchmarks/benchmarkTidy.php @@ -1,11 +1,13 @@ addOption( 'file', 'A filename which contains the input text', true, true ); + $this->addOption( 'file', 'Path to file containing the input text', false, true ); $this->addOption( 'driver', 'The Tidy driver name, or false to use the configured instance', false, true ); $this->addOption( 'tidy-config', 'JSON encoded value for the tidy configuration array', @@ -13,21 +15,22 @@ class BenchmarkTidy extends Maintenance { } public function execute() { - $html = file_get_contents( $this->getOption( 'file' ) ); + $file = $this->getOption( 'file', __DIR__ . '/tidy/australia-untidy.html.gz' ); + $html = $this->loadFile( $file ); if ( $html === false ) { - $this->error( "Unable to open input file", 1 ); + $this->fatalError( "Unable to open input file" ); } if ( $this->hasOption( 'driver' ) || $this->hasOption( 'tidy-config' ) ) { $config = json_decode( $this->getOption( 'tidy-config', '{}' ), true ); if ( !is_array( $config ) ) { - $this->error( "Invalid JSON tidy config", 1 ); + $this->fatalError( "Invalid JSON tidy config" ); } $config += [ 'driver' => $this->getOption( 'driver', 'RemexHtml' ) ]; $driver = MWTidy::factory( $config ); } else { $driver = MWTidy::singleton(); if ( !$driver ) { - $this->error( "Tidy disabled or not installed", 1 ); + $this->fatalError( "Tidy disabled or not installed" ); } } @@ -35,8 +38,7 @@ class BenchmarkTidy extends Maintenance { } private function benchmark( $driver, $html ) { - global $wgContLang; - + $contLang = MediaWikiServices::getInstance()->getContentLanguage(); $times = []; $innerCount = 10; $outerCount = 10; @@ -44,7 +46,7 @@ class BenchmarkTidy extends Maintenance { $t = microtime( true ); for ( $i = 0; $i < $innerCount; $i++ ) { $driver->tidy( $html ); - print $wgContLang->formatSize( memory_get_usage( true ) ) . "\n"; + print $contLang->formatSize( memory_get_usage( true ) ) . "\n"; } $t = ( ( microtime( true ) - $t ) / $innerCount ) * 1000; $times[] = $t; @@ -67,12 +69,11 @@ class BenchmarkTidy extends Maintenance { print "Median: $median ms\n"; print "Mean: $mean ms\n"; print "Maximum: $max ms\n"; - print "Memory usage: " . - $wgContLang->formatSize( memory_get_usage( true ) ) . "\n"; + print "Memory usage: " . $contLang->formatSize( memory_get_usage( true ) ) . "\n"; print "Peak memory usage: " . - $wgContLang->formatSize( memory_get_peak_usage( true ) ) . "\n"; + $contLang->formatSize( memory_get_peak_usage( true ) ) . "\n"; } } -$maintClass = 'BenchmarkTidy'; +$maintClass = BenchmarkTidy::class; require RUN_MAINTENANCE_IF_MAIN;