MediaWiki master
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
49 $this->bench( [
50 "Peast::parse ($filename)" => [
51 'function' => static function ( $content ) {
52 Peast\Peast::ES2016( $content )->parse();
53 },
54 'args' => [ $content ]
55 ]
56 ] );
57 }
58}
59
60$maintClass = BenchmarkJsValidate::class;
61require_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.