MediaWiki  1.34.0
benchmarkJSMinPlus.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( 'Benchmarks JSMinPlus.' );
35  $this->addOption( 'file', 'Path to JS file', true, true );
36  }
37 
38  public function execute() {
39  Wikimedia\suppressWarnings();
40  $content = file_get_contents( $this->getOption( 'file' ) );
41  Wikimedia\restoreWarnings();
42  if ( $content === false ) {
43  $this->fatalError( 'Unable to open input file' );
44  }
45 
46  $filename = basename( $this->getOption( 'file' ) );
47  $parser = new JSParser();
48 
49  $this->bench( [
50  "JSParser::parse ($filename)" => [
51  'function' => function ( $parser, $content, $filename ) {
52  $parser->parse( $content, $filename, 1 );
53  },
54  'args' => [ $parser, $content, $filename ]
55  ]
56  ] );
57  }
58 }
59 
60 $maintClass = BenchmarkJSMinPlus::class;
61 require_once RUN_MAINTENANCE_IF_MAIN;
BenchmarkJSMinPlus
Maintenance script that benchmarks JSMinPlus.
Definition: benchmarkJSMinPlus.php:29
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
BenchmarkJSMinPlus\$defaultCount
$defaultCount
Definition: benchmarkJSMinPlus.php:30
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
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:50
BenchmarkJSMinPlus\execute
execute()
Do the actual work.
Definition: benchmarkJSMinPlus.php:38
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
$maintClass
$maintClass
Definition: benchmarkJSMinPlus.php:60
$content
$content
Definition: router.php:78
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:302
BenchmarkJSMinPlus\__construct
__construct()
Default constructor.
Definition: benchmarkJSMinPlus.php:32
JSParser
Definition: jsminplus.php:674