MediaWiki master
benchmarkJsValidate.php
Go to the documentation of this file.
1<?php
9
10// @codeCoverageIgnoreStart
11require_once __DIR__ . '/../includes/Benchmarker.php';
12// @codeCoverageIgnoreEnd
13
23 protected $defaultCount = 10;
24
25 public function __construct() {
26 parent::__construct();
27 $this->addDescription( 'Measure JavaScript syntax validation.' );
28 $this->addOption( 'file', 'Path to JS file. Default: jquery', false, true );
29 }
30
31 public function execute() {
32 $file = $this->getOption( 'file', __DIR__ . '/data/jsmin/jquery-3.2.1.js.gz' );
33 $content = $this->loadFile( $file );
34 if ( $content === false ) {
35 $this->fatalError( 'Unable to open input file' );
36 }
37
38 $filename = basename( $file );
39
40 $this->bench( [
41 "Peast::parse ($filename)" => [
42 'function' => static function ( $content ) {
43 Peast\Peast::ES2017( $content )->parse();
44 },
45 'args' => [ $content ]
46 ]
47 ] );
48 }
49}
50
51// @codeCoverageIgnoreStart
52$maintClass = BenchmarkJsValidate::class;
53require_once RUN_MAINTENANCE_IF_MAIN;
54// @codeCoverageIgnoreEnd
Measure ResourceLoader syntax validation for user-supplied JavaScript.
execute()
Do the actual work.
__construct()
Default constructor.
Base class for benchmark scripts.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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.
addDescription( $text)
Set the description text.