MediaWiki  1.34.0
benchmarkJavaScriptMinifier.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/Benchmarker.php';
23 
30  protected $defaultCount = 10;
31 
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription( 'Benchmark for JavaScriptMinifier.' );
35  $this->addOption( 'file', 'Path to JavaScript file (may be gzipped)', false, true );
36  }
37 
38  public function execute() {
39  $file = $this->getOption( 'file', __DIR__ . '/jsmin/jquery-3.2.1.js.gz' );
40  $filename = basename( $file );
41  $content = $this->loadFile( $file );
42  if ( $content === false ) {
43  $this->fatalError( 'Unable to open input file' );
44  }
45 
46  $this->bench( [
47  "minify ($filename)" => [
48  'function' => [ JavaScriptMinifier::class, 'minify' ],
49  'args' => [ $content ],
50  ],
51  ] );
52  }
53 }
54 
55 $maintClass = BenchmarkJavaScriptMinifier::class;
56 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:504
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
BenchmarkJavaScriptMinifier
Maintenance script that benchmarks JavaScriptMinifier.
Definition: benchmarkJavaScriptMinifier.php:29
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:50
BenchmarkJavaScriptMinifier\$defaultCount
$defaultCount
Definition: benchmarkJavaScriptMinifier.php:30
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
$content
$content
Definition: router.php:78
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
BenchmarkJavaScriptMinifier\__construct
__construct()
Default constructor.
Definition: benchmarkJavaScriptMinifier.php:32
$maintClass
$maintClass
Definition: benchmarkJavaScriptMinifier.php:55
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:302
BenchmarkJavaScriptMinifier\execute
execute()
Do the actual work.
Definition: benchmarkJavaScriptMinifier.php:38
Benchmarker\loadFile
loadFile( $file)
Definition: Benchmarker.php:182