MediaWiki master
benchmarkJsValidate.php
Go to the documentation of this file.
1<?php
23
24// @codeCoverageIgnoreStart
25require_once __DIR__ . '/../includes/Benchmarker.php';
26// @codeCoverageIgnoreEnd
27
37 protected $defaultCount = 10;
38
39 public function __construct() {
40 parent::__construct();
41 $this->addDescription( 'Measure JavaScript syntax validation.' );
42 $this->addOption( 'file', 'Path to JS file. Default: jquery', false, true );
43 }
44
45 public function execute() {
46 $file = $this->getOption( 'file', __DIR__ . '/data/jsmin/jquery-3.2.1.js.gz' );
47 $content = $this->loadFile( $file );
48 if ( $content === false ) {
49 $this->fatalError( 'Unable to open input file' );
50 }
51
52 $filename = basename( $file );
53
54 $this->bench( [
55 "Peast::parse ($filename)" => [
56 'function' => static function ( $content ) {
57 Peast\Peast::ES2016( $content )->parse();
58 },
59 'args' => [ $content ]
60 ]
61 ] );
62 }
63}
64
65// @codeCoverageIgnoreStart
66$maintClass = BenchmarkJsValidate::class;
67require_once RUN_MAINTENANCE_IF_MAIN;
68// @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.