MediaWiki REL1_41
benchmarkJsValidate.php
Go to the documentation of this file.
1<?php
22require_once __DIR__ . '/../includes/Benchmarker.php';
23
32 protected $defaultCount = 10;
33
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Measure JavaScript syntax validation.' );
37 $this->addOption( 'file', 'Path to JS file. Default: jquery', false, true );
38 }
39
40 public function execute() {
41 $file = $this->getOption( 'file', __DIR__ . '/data/jsmin/jquery-3.2.1.js.gz' );
42 $content = $this->loadFile( $file );
43 if ( $content === false ) {
44 $this->fatalError( 'Unable to open input file' );
45 }
46
47 $filename = basename( $file );
48 $parser = new JSParser();
49
50 $this->bench( [
51 "JSParser::parse ($filename)" => [
52 'function' => static function ( $parser, $content, $filename ) {
53 // phpcs:ignore Generic.PHP.NoSilencedErrors
54 @$parser->parse( $content, $filename, 1 );
55 },
56 'args' => [ $parser, $content, $filename ]
57 ]
58 ] );
59 }
60}
61
62$maintClass = BenchmarkJsValidate::class;
63require_once RUN_MAINTENANCE_IF_MAIN;
Measure ResourceLoader syntax validation for user-supplied JavaScript.
execute()
Do the actual work.
__construct()
Default constructor.
Base class for benchmark scripts.
bench(array $benchs)
loadFile( $file)
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$content
Definition router.php:76
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42