MediaWiki
master
Toggle main menu visibility
benchmarkTidy.php
Go to the documentation of this file.
1
<?php
7
8
use
MediaWiki\Maintenance\Benchmarker
;
9
use Wikimedia\Timestamp\ConvertibleTimestamp;
10
11
// @codeCoverageIgnoreStart
12
require_once __DIR__ .
'/../includes/Benchmarker.php'
;
13
// @codeCoverageIgnoreEnd
14
15
class
BenchmarkTidy
extends
Benchmarker
{
16
public
function
__construct
() {
17
parent::__construct();
18
$this->
addOption
(
'file'
,
'Path to file containing the input text'
,
false
,
true
);
19
}
20
21
public
function
execute
() {
22
$file = $this->
getOption
(
'file'
, __DIR__ .
'/data/tidy/australia-untidy.html.gz'
);
23
$html = $this->
loadFile
( $file );
24
if
( $html ===
false
) {
25
$this->
fatalError
(
"Unable to open input file"
);
26
}
27
28
$this->benchmark( $html );
29
}
30
31
private
function
benchmark(
string
$html ) {
32
$services = $this->
getServiceContainer
();
33
$contLang = $services->getContentLanguage();
34
$tidy = $services->getTidy();
35
$times = [];
36
$innerCount = 10;
37
$outerCount = 10;
38
for
( $j = 1; $j <= $outerCount; $j++ ) {
39
$t = ConvertibleTimestamp::hrtime();
40
for
( $i = 0; $i < $innerCount; $i++ ) {
41
$tidy->tidy( $html );
42
print $contLang->formatSize( memory_get_usage(
true
) ) .
"\n"
;
43
}
44
$t
= ( ( ConvertibleTimestamp::hrtime() -
$t
) / $innerCount ) / 1e6;
45
$times[] =
$t
;
46
print
"Run $j: $t\n"
;
47
}
48
print
"\n"
;
49
50
sort( $times, SORT_NUMERIC );
51
$n = $outerCount;
52
$min = $times[0];
53
$max = end( $times );
54
if
( $n % 2 ) {
55
// @phan-suppress-next-line PhanTypeMismatchDimFetch
56
$median = $times[ ( $n - 1 ) / 2 ];
57
}
else
{
58
$median = ( $times[$n / 2] + $times[$n / 2 - 1] ) / 2;
59
}
60
$mean = array_sum( $times ) / $n;
61
62
print
"Minimum: $min ms\n"
;
63
print
"Median: $median ms\n"
;
64
print
"Mean: $mean ms\n"
;
65
print
"Maximum: $max ms\n"
;
66
print
"Memory usage: "
. $contLang->formatSize( memory_get_usage(
true
) ) .
"\n"
;
67
print
"Peak memory usage: "
.
68
$contLang->formatSize( memory_get_peak_usage(
true
) ) .
"\n"
;
69
}
70
}
71
72
// @codeCoverageIgnoreStart
73
$maintClass
= BenchmarkTidy::class;
74
require_once RUN_MAINTENANCE_IF_MAIN;
75
// @codeCoverageIgnoreEnd
$maintClass
$maintClass
Definition
addChangeTag.php:56
BenchmarkTidy
Definition
benchmarkTidy.php:15
BenchmarkTidy\__construct
__construct()
Default constructor.
Definition
benchmarkTidy.php:16
BenchmarkTidy\execute
execute()
Do the actual work.
Definition
benchmarkTidy.php:21
MediaWiki\Maintenance\Benchmarker
Base class for benchmark scripts.
Definition
Benchmarker.php:29
MediaWiki\Maintenance\Benchmarker\loadFile
loadFile( $file)
Definition
Benchmarker.php:209
MediaWiki\Maintenance\Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition
Maintenance.php:545
MediaWiki\Maintenance\Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition
Maintenance.php:265
MediaWiki\Maintenance\Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition
Maintenance.php:299
MediaWiki\Maintenance\Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:671
MediaWiki\Parser\CoreParserFunctions\null\$t
$t
Definition
CoreParserFunctions.php:828
maintenance
benchmarks
benchmarkTidy.php
Generated on
for MediaWiki by
1.18.0