MediaWiki  master
benchmarkJSMinPlus.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/../includes/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. Default: jquery', false, true );
36  }
37 
38  public function execute() {
39  $file = $this->getOption( 'file', __DIR__ . '/data/jsmin/jquery-3.2.1.js.gz' );
40  $content = $this->loadFile( $file );
41  if ( $content === false ) {
42  $this->fatalError( 'Unable to open input file' );
43  }
44 
45  $filename = basename( $file );
46  $parser = new JSParser();
47 
48  $this->bench( [
49  "JSParser::parse ($filename)" => [
50  'function' => static function ( $parser, $content, $filename ) {
51  $parser->parse( $content, $filename, 1 );
52  },
53  'args' => [ $parser, $content, $filename ]
54  ]
55  ] );
56  }
57 }
58 
59 $maintClass = BenchmarkJSMinPlus::class;
60 require_once RUN_MAINTENANCE_IF_MAIN;
BenchmarkJSMinPlus
Maintenance script that benchmarks JSMinPlus.
Definition: benchmarkJSMinPlus.php:29
BenchmarkJSMinPlus\$defaultCount
$defaultCount
Definition: benchmarkJSMinPlus.php:30
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
$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:49
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:249
$maintClass
$maintClass
Definition: benchmarkJSMinPlus.php:59
$content
$content
Definition: router.php:76
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:286
Benchmarker\loadFile
loadFile( $file)
Definition: Benchmarker.php:202
BenchmarkJSMinPlus\__construct
__construct()
Default constructor.
Definition: benchmarkJSMinPlus.php:32
JSParser
Definition: jsminplus.php:675