Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / maintenance / benchmarks / benchmarkCSSMin.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Benchmark
20 * @author Timo Tijhof
21 */
22
23 require_once __DIR__ . '/Benchmarker.php';
24
25 /**
26 * Maintenance script that benchmarks CSSMin.
27 *
28 * @ingroup Benchmark
29 */
30 class BenchmarkCSSMin extends Benchmarker {
31 public function __construct() {
32 parent::__construct();
33 $this->addDescription( 'Benchmarks CSSMin.' );
34 $this->addOption( 'file', 'Path to CSS file (may be gzipped)', false, true );
35 $this->addOption( 'out', 'Echo output of one run to stdout for inspection', false, false );
36 }
37
38 public function execute() {
39 $file = $this->getOption( 'file', __DIR__ . '/cssmin/styles.css' );
40 $filename = basename( $file );
41 $css = $this->loadFile( $file );
42
43 if ( $this->hasOption( 'out' ) ) {
44 echo "## minify\n\n",
45 CSSMin::minify( $css ),
46 "\n\n";
47 echo "## remap\n\n",
48 CSSMin::remap( $css, dirname( $file ), 'https://example.org/test/', true ),
49 "\n";
50 return;
51 }
52
53 $this->bench( [
54 "minify ($filename)" => [
55 'function' => [ 'CSSMin', 'minify' ],
56 'args' => [ $css ]
57 ],
58 "remap ($filename)" => [
59 'function' => [ 'CSSMin', 'remap' ],
60 'args' => [ $css, dirname( $file ), 'https://example.org/test/', true ]
61 ],
62 ] );
63 }
64
65 private function loadFile( $file ) {
66 $css = file_get_contents( $file );
67 // Detect GZIP compression header
68 if ( substr( $css, 0, 2 ) === "\037\213" ) {
69 $css = gzdecode( $css );
70 }
71 return $css;
72 }
73 }
74
75 $maintClass = 'BenchmarkCSSMin';
76 require_once RUN_MAINTENANCE_IF_MAIN;