benchmarks: Add benchmark for JavaScriptMinifier
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 13 Aug 2018 16:23:53 +0000 (17:23 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 13 Aug 2018 18:12:21 +0000 (18:12 +0000)
Bug: T201606
Change-Id: I40fe0b2799b210e552b96f9fadc2b394928ec729

autoload.php
maintenance/benchmarks/benchmarkJavaScriptMinifier.php [new file with mode: 0644]
maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz [new file with mode: 0644]

index d3ab3af..1c1eeef 100644 (file)
@@ -195,6 +195,7 @@ $wgAutoloadLocalClasses = [
        'BenchmarkDeleteTruncate' => __DIR__ . '/maintenance/benchmarks/bench_delete_truncate.php',
        'BenchmarkHooks' => __DIR__ . '/maintenance/benchmarks/benchmarkHooks.php',
        'BenchmarkJSMinPlus' => __DIR__ . '/maintenance/benchmarks/benchmarkJSMinPlus.php',
+       'BenchmarkJavaScriptMinifier' => __DIR__ . '/maintenance/benchmarks/benchmarkJavaScriptMinifier.php',
        'BenchmarkLruHash' => __DIR__ . '/maintenance/benchmarks/benchmarkLruHash.php',
        'BenchmarkParse' => __DIR__ . '/maintenance/benchmarks/benchmarkParse.php',
        'BenchmarkPurge' => __DIR__ . '/maintenance/benchmarks/benchmarkPurge.php',
diff --git a/maintenance/benchmarks/benchmarkJavaScriptMinifier.php b/maintenance/benchmarks/benchmarkJavaScriptMinifier.php
new file mode 100644 (file)
index 0000000..bb75660
--- /dev/null
@@ -0,0 +1,57 @@
+<?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
+ * @author Timo Tijhof
+ */
+
+require_once __DIR__ . '/Benchmarker.php';
+
+/**
+ * Maintenance script that benchmarks JavaScriptMinifier.
+ *
+ * @ingroup Benchmark
+ */
+class BenchmarkJavaScriptMinifier extends Benchmarker {
+       protected $defaultCount = 10;
+
+       public function __construct() {
+               parent::__construct();
+               $this->addDescription( 'Benchmark for JavaScriptMinifier.' );
+               $this->addOption( 'file', 'Path to JavaScript file (may be gzipped)', false, true );
+       }
+
+       public function execute() {
+               $file = $this->getOption( 'file', __DIR__ . '/jsmin/jquery-3.2.1.js.gz' );
+               $filename = basename( $file );
+               $content = $this->loadFile( $file );
+               if ( $content === false ) {
+                       $this->fatalError( 'Unable to open input file' );
+               }
+
+               $this->bench( [
+                       "minify ($filename)" => [
+                               'function' => [ JavaScriptMinifier::class, 'minify' ],
+                               'args' => [ $content ],
+                       ],
+               ] );
+       }
+}
+
+$maintClass = BenchmarkJavaScriptMinifier::class;
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz b/maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz
new file mode 100644 (file)
index 0000000..2e8e9b2
Binary files /dev/null and b/maintenance/benchmarks/jsmin/jquery-3.2.1.js.gz differ