MediaWiki REL1_30
benchmarkTidy.php
Go to the documentation of this file.
1<?php
2
3require __DIR__ . '/../Maintenance.php';
4
6 public function __construct() {
7 parent::__construct();
8 $this->addOption( 'file', 'A filename which contains the input text', true, true );
9 $this->addOption( 'driver', 'The Tidy driver name, or false to use the configured instance',
10 false, true );
11 $this->addOption( 'tidy-config', 'JSON encoded value for the tidy configuration array',
12 false, true );
13 }
14
15 public function execute() {
16 $html = file_get_contents( $this->getOption( 'file' ) );
17 if ( $html === false ) {
18 $this->error( "Unable to open input file", 1 );
19 }
20 if ( $this->hasOption( 'driver' ) || $this->hasOption( 'tidy-config' ) ) {
21 $config = json_decode( $this->getOption( 'tidy-config', '{}' ), true );
22 if ( !is_array( $config ) ) {
23 $this->error( "Invalid JSON tidy config", 1 );
24 }
25 $config += [ 'driver' => $this->getOption( 'driver', 'RemexHtml' ) ];
26 $driver = MWTidy::factory( $config );
27 } else {
28 $driver = MWTidy::singleton();
29 if ( !$driver ) {
30 $this->error( "Tidy disabled or not installed", 1 );
31 }
32 }
33
34 $this->benchmark( $driver, $html );
35 }
36
37 private function benchmark( $driver, $html ) {
38 global $wgContLang;
39
40 $times = [];
41 $innerCount = 10;
42 $outerCount = 10;
43 for ( $j = 1; $j <= $outerCount; $j++ ) {
44 $t = microtime( true );
45 for ( $i = 0; $i < $innerCount; $i++ ) {
46 $driver->tidy( $html );
47 print $wgContLang->formatSize( memory_get_usage( true ) ) . "\n";
48 }
49 $t = ( ( microtime( true ) - $t ) / $innerCount ) * 1000;
50 $times[] = $t;
51 print "Run $j: $t\n";
52 }
53 print "\n";
54
55 sort( $times, SORT_NUMERIC );
56 $n = $outerCount;
57 $min = $times[0];
58 $max = end( $times );
59 if ( $n % 2 ) {
60 $median = $times[ ( $n - 1 ) / 2 ];
61 } else {
62 $median = ( $times[$n / 2] + $times[$n / 2 - 1] ) / 2;
63 }
64 $mean = array_sum( $times ) / $n;
65
66 print "Minimum: $min ms\n";
67 print "Median: $median ms\n";
68 print "Mean: $mean ms\n";
69 print "Maximum: $max ms\n";
70 print "Memory usage: " .
71 $wgContLang->formatSize( memory_get_usage( true ) ) . "\n";
72 print "Peak memory usage: " .
73 $wgContLang->formatSize( memory_get_peak_usage( true ) ) . "\n";
74 }
75}
76
77$maintClass = 'BenchmarkTidy';
$maintClass
benchmark( $driver, $html)
__construct()
Default constructor.
execute()
Do the actual work.
static singleton()
Definition MWTidy.php:86
static factory(array $config)
Create a new Tidy driver object from configuration.
Definition MWTidy.php:124
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
hasOption( $name)
Checks to see if a particular param exists.
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.
Config $config
Accessible via getConfig()
print
Definition cleanup.php:99
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:1983
require_once RUN_MAINTENANCE_IF_MAIN