MediaWiki  master
benchmarkEval.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/../includes/Benchmarker.php';
4 
16 class BenchmarkEval extends Benchmarker {
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;
51 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance\hasArg
hasArg( $argId=0)
Does a given argument exist?
Definition: Maintenance.php:338
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:49
BenchmarkEval\__construct
__construct()
Default constructor.
Definition: benchmarkEval.php:17
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:249
$maintClass
$maintClass
Definition: benchmarkEval.php:50
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
BenchmarkEval
Benchmark any provided code for ad-hoc benchmarks.
Definition: benchmarkEval.php:16
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:286
BenchmarkEval\execute
execute()
Do the actual work.
Definition: benchmarkEval.php:27
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:300
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option was set.
Definition: Maintenance.php:271
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:353