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