MediaWiki REL1_39
benchmarkEval.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/../includes/Benchmarker.php';
4
17 public function __construct() {
18 parent::__construct();
19 $this->addOption( 'inner',
20 'Inner loop iterations', false, true );
21 $this->addOption( 'code',
22 'The code to run',
23 false, true, 'e' );
24 $this->addArg( 'input-file', 'Input file', false );
25 }
26
27 public function execute() {
28 if ( $this->hasOption( 'code' ) ) {
29 $code = $this->getOption( 'code' );
30 } elseif ( $this->hasArg( 0 ) ) {
31 $code = file_get_contents( $this->getArg( 0 ) );
32 if ( $code === false ) {
33 $this->fatalError( "Unable to read input file" );
34 }
35 } else {
36 fwrite( STDERR, "Reading from stdin...\n" );
37 $code = stream_get_contents( STDIN );
38 }
39 $code .= ';';
40 $inner = $this->getOption( 'inner', 1 );
41 if ( $inner > 1 ) {
42 $code = "for ( \$__i = 0; \$__i < $inner; \$__i++ ) { $code }";
43 }
44 $code = "function wfBenchmarkEvalBody () { $code }";
45 eval( $code );
46 $this->bench( [ 'eval' => [ 'function' => 'wfBenchmarkEvalBody' ] ] );
47 }
48}
49
50$maintClass = BenchmarkEval::class;
51require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
Benchmark any provided code for ad-hoc benchmarks.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
bench(array $benchs)
addArg( $arg, $description, $required=true)
Add some args that are needed.
hasArg( $argId=0)
Does a given argument exist?
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.