From bccbafd6d857224a495d113d40bc7b7d7139f4e9 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 13 Aug 2018 17:12:01 +0100 Subject: [PATCH] benchmarks: Add a default to the 'file' option of benchmarkTidy.php * Move the fixture to its own directory. * Add a default to the 'file' option. * Use loadFile() so that it works by default without requiring the user to unzip it first. Change-Id: I9edf2c19ce5730b72bad3a33c60eda588072a3cf --- maintenance/benchmarks/Benchmarker.php | 14 ++++++++++++++ maintenance/benchmarks/benchmarkCSSMin.php | 9 --------- maintenance/benchmarks/benchmarkTidy.php | 9 +++++---- .../{ => tidy}/australia-untidy.html.gz | Bin 4 files changed, 19 insertions(+), 13 deletions(-) rename maintenance/benchmarks/{ => tidy}/australia-untidy.html.gz (100%) diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index e1eef07e07..04aee80210 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -162,4 +162,18 @@ abstract class Benchmarker extends Maintenance { $this->lang->formatSize( memory_get_peak_usage( true ) ) ) ); } + + /** + * @since 1.32 + * @param string $file Path to file (maybe compressed with gzip) + * @return string Contents of file + */ + protected function loadFile( $file ) { + $content = file_get_contents( $file ); + // Detect GZIP compression header + if ( substr( $content, 0, 2 ) === "\037\213" ) { + $content = gzdecode( $content ); + } + return $content; + } } diff --git a/maintenance/benchmarks/benchmarkCSSMin.php b/maintenance/benchmarks/benchmarkCSSMin.php index a7d998d2d7..8e2acb2987 100644 --- a/maintenance/benchmarks/benchmarkCSSMin.php +++ b/maintenance/benchmarks/benchmarkCSSMin.php @@ -61,15 +61,6 @@ class BenchmarkCSSMin extends Benchmarker { ], ] ); } - - private function loadFile( $file ) { - $css = file_get_contents( $file ); - // Detect GZIP compression header - if ( substr( $css, 0, 2 ) === "\037\213" ) { - $css = gzdecode( $css ); - } - return $css; - } } $maintClass = BenchmarkCSSMin::class; diff --git a/maintenance/benchmarks/benchmarkTidy.php b/maintenance/benchmarks/benchmarkTidy.php index 5a432fb94e..e9a30f9b1f 100644 --- a/maintenance/benchmarks/benchmarkTidy.php +++ b/maintenance/benchmarks/benchmarkTidy.php @@ -2,12 +2,12 @@ use MediaWiki\MediaWikiServices; -require __DIR__ . '/../Maintenance.php'; +require __DIR__ . '/Benchmarker.php'; -class BenchmarkTidy extends Maintenance { +class BenchmarkTidy extends Benchmarker { public function __construct() { parent::__construct(); - $this->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', @@ -15,7 +15,8 @@ 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->fatalError( "Unable to open input file" ); } diff --git a/maintenance/benchmarks/australia-untidy.html.gz b/maintenance/benchmarks/tidy/australia-untidy.html.gz similarity index 100% rename from maintenance/benchmarks/australia-untidy.html.gz rename to maintenance/benchmarks/tidy/australia-untidy.html.gz -- 2.20.1