2017-06-15 17:06:10 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Benchmark
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2019-12-18 01:24:42 +00:00
|
|
|
require_once __DIR__ . '/../includes/Benchmarker.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2017-06-15 17:06:10 +00:00
|
|
|
|
|
|
|
|
/**
|
2023-10-03 00:01:22 +00:00
|
|
|
* Measure ResourceLoader syntax validation for user-supplied JavaScript.
|
2017-06-15 17:06:10 +00:00
|
|
|
*
|
2023-10-03 00:01:22 +00:00
|
|
|
* @see ResourceLoader\Module::validateScriptFile
|
|
|
|
|
* @see JSParseHelper
|
2017-06-15 17:06:10 +00:00
|
|
|
* @ingroup Benchmark
|
|
|
|
|
*/
|
2023-10-03 00:01:22 +00:00
|
|
|
class BenchmarkJsValidate extends Benchmarker {
|
2024-09-12 19:59:28 +00:00
|
|
|
/** @inheritDoc */
|
2017-06-15 17:06:10 +00:00
|
|
|
protected $defaultCount = 10;
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2023-10-03 00:01:22 +00:00
|
|
|
$this->addDescription( 'Measure JavaScript syntax validation.' );
|
2021-08-26 03:17:18 +00:00
|
|
|
$this->addOption( 'file', 'Path to JS file. Default: jquery', false, true );
|
2017-06-15 17:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2021-08-26 03:17:18 +00:00
|
|
|
$file = $this->getOption( 'file', __DIR__ . '/data/jsmin/jquery-3.2.1.js.gz' );
|
|
|
|
|
$content = $this->loadFile( $file );
|
2017-06-15 17:06:10 +00:00
|
|
|
if ( $content === false ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( 'Unable to open input file' );
|
2017-06-15 17:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-26 03:17:18 +00:00
|
|
|
$filename = basename( $file );
|
2023-10-03 01:22:48 +00:00
|
|
|
|
|
|
|
|
$this->bench( [
|
|
|
|
|
"Peast::parse ($filename)" => [
|
|
|
|
|
'function' => static function ( $content ) {
|
|
|
|
|
Peast\Peast::ES2016( $content )->parse();
|
|
|
|
|
},
|
|
|
|
|
'args' => [ $content ]
|
|
|
|
|
]
|
|
|
|
|
] );
|
2017-06-15 17:06:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2023-10-03 00:01:22 +00:00
|
|
|
$maintClass = BenchmarkJsValidate::class;
|
2017-06-15 17:06:10 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|