MediaWiki
master
Toggle main menu visibility
benchmarkEval.php
Go to the documentation of this file.
1
<?php
2
3
use
MediaWiki\Maintenance\Benchmarker
;
4
5
// @codeCoverageIgnoreStart
6
require_once __DIR__ .
'/../includes/Benchmarker.php'
;
7
// @codeCoverageIgnoreEnd
8
20
class
BenchmarkEval
extends
Benchmarker
{
21
public
function
__construct
() {
22
parent::__construct();
23
$this->
addOption
(
'inner'
,
24
'Inner loop iterations'
,
false
,
true
);
25
$this->
addOption
(
'code'
,
26
'The code to run'
,
27
false
,
true
,
'e'
);
28
$this->
addOption
(
'setup'
,
29
'Code to run once before the first iteration'
,
30
false
,
true
);
31
$this->
addArg
(
'input-file'
,
'Input file for measured code body'
,
false
);
32
}
33
34
public
function
execute
() {
35
if
( $this->
hasOption
(
'setup'
) ) {
36
$setupCode = $this->
getOption
(
'setup'
) .
';'
;
37
// phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.eval
38
eval( $setupCode );
39
}
40
41
if
( $this->
hasOption
(
'code'
) ) {
42
$code = $this->
getOption
(
'code'
);
43
} elseif ( $this->
hasArg
( 0 ) ) {
44
$code = file_get_contents( $this->
getArg
( 0 ) );
45
if
( $code ===
false
) {
46
$this->
fatalError
(
"Unable to read input file"
);
47
}
48
}
else
{
49
fwrite( STDERR,
"Reading from stdin...\n"
);
50
$code = stream_get_contents( STDIN );
51
}
52
$code .=
';'
;
53
$inner = $this->
getOption
(
'inner'
, 1 );
54
if
( $inner > 1 ) {
55
$code =
"for ( \$__i = 0; \$__i < $inner; \$__i++ ) { $code }"
;
56
}
57
$code =
"function wfBenchmarkEvalBody () { $code }"
;
58
// phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.eval
59
eval( $code );
60
$this->
bench
( [
'eval'
=> [
'function'
=>
'wfBenchmarkEvalBody'
] ] );
61
}
62
}
63
64
// @codeCoverageIgnoreStart
65
$maintClass
= BenchmarkEval::class;
66
require_once RUN_MAINTENANCE_IF_MAIN;
67
// @codeCoverageIgnoreEnd
$maintClass
$maintClass
Definition
addChangeTag.php:56
BenchmarkEval
Benchmark any provided code for ad-hoc benchmarks.
Definition
benchmarkEval.php:20
BenchmarkEval\__construct
__construct()
Default constructor.
Definition
benchmarkEval.php:21
BenchmarkEval\execute
execute()
Do the actual work.
Definition
benchmarkEval.php:34
MediaWiki\Maintenance\Benchmarker
Base class for benchmark scripts.
Definition
Benchmarker.php:29
MediaWiki\Maintenance\Benchmarker\bench
bench(array $benchs)
Definition
Benchmarker.php:39
MediaWiki\Maintenance\Maintenance\addArg
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
Definition
Maintenance.php:310
MediaWiki\Maintenance\Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition
Maintenance.php:357
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\hasOption
hasOption( $name)
Checks to see if a particular option was set.
Definition
Maintenance.php:284
MediaWiki\Maintenance\Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition
Maintenance.php:299
MediaWiki\Maintenance\Maintenance\hasArg
hasArg( $argId=0)
Does a given argument exist?
Definition
Maintenance.php:345
maintenance
benchmarks
benchmarkEval.php
Generated on
for MediaWiki by
1.18.0