MediaWiki REL1_31
benchmarkCSSMin.php
Go to the documentation of this file.
1<?php
23require_once __DIR__ . '/Benchmarker.php';
24
31 public function __construct() {
32 parent::__construct();
33 $this->addDescription( 'Benchmarks CSSMin.' );
34 $this->addOption( 'file', 'Path to CSS file (may be gzipped)', false, true );
35 $this->addOption( 'out', 'Echo output of one run to stdout for inspection', false, false );
36 }
37
38 public function execute() {
39 $file = $this->getOption( 'file', __DIR__ . '/cssmin/styles.css' );
40 $filename = basename( $file );
41 $css = $this->loadFile( $file );
42
43 if ( $this->hasOption( 'out' ) ) {
44 echo "## minify\n\n",
45 CSSMin::minify( $css ),
46 "\n\n";
47 echo "## remap\n\n",
48 CSSMin::remap( $css, dirname( $file ), 'https://example.org/test/', true ),
49 "\n";
50 return;
51 }
52
53 $this->bench( [
54 "minify ($filename)" => [
55 'function' => [ CSSMin::class, 'minify' ],
56 'args' => [ $css ]
57 ],
58 "remap ($filename)" => [
59 'function' => [ CSSMin::class, 'remap' ],
60 'args' => [ $css, dirname( $file ), 'https://example.org/test/', true ]
61 ],
62 ] );
63 }
64
65 private function loadFile( $file ) {
66 $css = file_get_contents( $file );
67 // Detect GZIP compression header
68 if ( substr( $css, 0, 2 ) === "\037\213" ) {
69 $css = gzdecode( $css );
70 }
71 return $css;
72 }
73}
74
75$maintClass = BenchmarkCSSMin::class;
76require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
Maintenance script that benchmarks CSSMin.
execute()
Do the actual work.
__construct()
Default constructor.
Base class for benchmark scripts.
bench(array $benchs)
hasOption( $name)
Checks to see if a particular param exists.
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.
require_once RUN_MAINTENANCE_IF_MAIN