MediaWiki  1.23.8
Benchmarker.php
Go to the documentation of this file.
1 <?php
30 require_once __DIR__ . '/../Maintenance.php';
31 
37 abstract class Benchmarker extends Maintenance {
38  private $results;
39 
40  public function __construct() {
41  parent::__construct();
42  $this->addOption( 'count', "How many time to run a benchmark", false, true );
43  }
44 
45  public function bench( array $benchs ) {
46  $bench_number = 0;
47  $count = $this->getOption( 'count', 100 );
48 
49  foreach( $benchs as $bench ) {
50  // handle empty args
51  if( !array_key_exists( 'args', $bench ) ) {
52  $bench['args'] = array();
53  }
54 
55  $bench_number++;
56  $start = microtime( true );
57  for( $i = 0; $i < $count; $i++ ) {
58  call_user_func_array( $bench['function'], $bench['args'] );
59  }
60  $delta = microtime( true ) - $start;
61 
62  // function passed as a callback
63  if( is_array( $bench['function'] ) ) {
64  $ret = get_class( $bench['function'][0] ) . '->' . $bench['function'][1];
65  $bench['function'] = $ret;
66  }
67 
68  $this->results[$bench_number] = array(
69  'function' => $bench['function'],
70  'arguments' => $bench['args'],
71  'count' => $count,
72  'delta' => $delta,
73  'average' => $delta / $count,
74  );
75  }
76  }
77 
78  public function getFormattedResults() {
79  $ret = '';
80  foreach( $this->results as $res ) {
81  // show function with args
82  $ret .= sprintf( "%s times: function %s(%s) :\n",
83  $res['count'],
84  $res['function'],
85  join( ', ', $res['arguments'] )
86  );
87  $ret .= sprintf( " %6.2fms (%6.2fms each)\n",
88  $res['delta'] * 1000,
89  $res['average'] * 1000
90  );
91  }
92  return $ret;
93  }
94 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Benchmarker\getFormattedResults
getFormattedResults()
Definition: Benchmarker.php:78
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
$ret
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 & $ret
Definition: hooks.txt:1530
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:45
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:37
$count
$count
Definition: UtfNormalTest2.php:96
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
Benchmarker\$results
$results
Definition: Benchmarker.php:38
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Benchmarker\__construct
__construct()
Default constructor.
Definition: Benchmarker.php:40
$res
$res
Definition: database.txt:21