From: Timo Tijhof Date: Thu, 4 May 2017 04:00:14 +0000 (-0700) Subject: resourceloader: Add CSSMin benchmarks X-Git-Tag: 1.31.0-rc.0~3329^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=0ec9359653864e19a733775c00c00a2b03c64bfe;p=lhc%2Fweb%2Fwiklou.git resourceloader: Add CSSMin benchmarks Usage: # Run default benchmark $ php maintenance/benchmarks/benchmarkCSSMin.php # Use custom file $ php maintenance/benchmarks/benchmarkCSSMin.php --file resources/lib/qunitjs/qunit.css # Debug the output for inspection (no benchmark) $ php maintenance/benchmarks/benchmarkCSSMin.php --out Change-Id: I70d118131d0ff16d1a811b2de1328ea622b7ca69 --- diff --git a/autoload.php b/autoload.php index 1141c391fb..e5161f1cb7 100644 --- a/autoload.php +++ b/autoload.php @@ -188,6 +188,7 @@ $wgAutoloadLocalClasses = [ 'BenchUtf8TitleCheck' => __DIR__ . '/maintenance/benchmarks/bench_utf8_title_check.php', 'BenchWfIsWindows' => __DIR__ . '/maintenance/benchmarks/bench_wfIsWindows.php', 'BenchWikimediaBaseConvert' => __DIR__ . '/maintenance/benchmarks/bench_Wikimedia_base_convert.php', + 'BenchmarkCSSMin' => __DIR__ . '/maintenance/benchmarks/benchmarkCSSMin.php', 'BenchmarkDeleteTruncate' => __DIR__ . '/maintenance/benchmarks/bench_delete_truncate.php', 'BenchmarkHooks' => __DIR__ . '/maintenance/benchmarks/benchmarkHooks.php', 'BenchmarkParse' => __DIR__ . '/maintenance/benchmarks/benchmarkParse.php', diff --git a/maintenance/benchmarks/benchmarkCSSMin.php b/maintenance/benchmarks/benchmarkCSSMin.php new file mode 100644 index 0000000000..3eaa88dcf9 --- /dev/null +++ b/maintenance/benchmarks/benchmarkCSSMin.php @@ -0,0 +1,76 @@ +addDescription( 'Benchmarks CSSMin.' ); + $this->addOption( 'file', 'Path to CSS file (may be gzipped)', false, true ); + $this->addOption( 'out', 'Echo output of one run to stdout for inspection', false, false ); + } + + public function execute() { + $file = $this->getOption( 'file', __DIR__ . '/cssmin/styles.css' ); + $filename = basename( $file ); + $css = $this->loadFile( $file ); + + if ( $this->hasOption( 'out' ) ) { + echo "## minify\n\n", + CSSMin::minify( $css ), + "\n\n"; + echo "## remap\n\n", + CSSMin::remap( $css, dirname( $file ), 'https://example.org/test/', true ), + "\n"; + return; + } + + $this->bench( [ + "minify ($filename)" => [ + 'function' => [ 'CSSMin', 'minify' ], + 'args' => [ $css ] + ], + "remap ($filename)" => [ + 'function' => [ 'CSSMin', 'remap' ], + 'args' => [ $css, dirname( $file ), 'https://example.org/test/', true ] + ], + ] ); + } + + 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'; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/cssmin/circle.svg b/maintenance/benchmarks/cssmin/circle.svg new file mode 100644 index 0000000000..6b7d1afd87 --- /dev/null +++ b/maintenance/benchmarks/cssmin/circle.svg @@ -0,0 +1,4 @@ + + + + diff --git a/maintenance/benchmarks/cssmin/styles.css b/maintenance/benchmarks/cssmin/styles.css new file mode 100644 index 0000000000..3cc15206a0 --- /dev/null +++ b/maintenance/benchmarks/cssmin/styles.css @@ -0,0 +1,32 @@ +/** + * Header + */ + +.foo { + background: url(wiki.png); +} + +.foo { + background: url(unknown.png); +} + +.foo { + background: url(https://example.org/foo.png); + background: url('https://example.org/foo.png'); + background: url("https://example.org/foo.png"); +} + +.foo { + /* @embed */ + background: url(wiki.png); +} + +.foo { + /* @embed */ + background: url(circle.svg); +} + +.foo { + /* @embed */ + background: url(wiki.png), url(wiki.png); +} diff --git a/maintenance/benchmarks/cssmin/wiki.png b/maintenance/benchmarks/cssmin/wiki.png new file mode 100644 index 0000000000..8c42118385 Binary files /dev/null and b/maintenance/benchmarks/cssmin/wiki.png differ