MediaWiki  1.32.5
benchmarkLruHash.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/Benchmarker.php';
23 
30  protected $defaultCount = 1000;
31 
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription( 'Benchmarks HashBagOStuff and MapCacheLRU.' );
35  $this->addOption( 'method', 'One of "construct" or "set". Default: [All]', false, true );
36  }
37 
38  public function execute() {
39  $exampleKeys = [];
40  $max = 100;
41  $count = 500;
42  while ( $count-- ) {
43  $exampleKeys[] = wfRandomString();
44  }
45  // 1000 keys (1...500, 500...1)
46  $keys = array_merge( $exampleKeys, array_reverse( $exampleKeys ) );
47 
48  $method = $this->getOption( 'method' );
49  $benches = [];
50 
51  if ( !$method || $method === 'construct' ) {
52  $benches['HashBagOStuff::__construct'] = [
53  'function' => function () use ( $max ) {
54  $obj = new HashBagOStuff( [ 'maxKeys' => $max ] );
55  },
56  ];
57  $benches['MapCacheLRU::__construct'] = [
58  'function' => function () use ( $max ) {
59  $obj = new MapCacheLRU( $max );
60  },
61  ];
62  }
63 
64  if ( !$method || $method === 'set' ) {
65  // For the set bechmark, do object creation in setup (not measured)
66  $hObj = null;
67  $benches['HashBagOStuff::set'] = [
68  'setup' => function () use ( &$hObj, $max ) {
69  $hObj = new HashBagOStuff( [ 'maxKeys' => $max ] );
70  },
71  'function' => function () use ( &$hObj, &$keys ) {
72  foreach ( $keys as $i => $key ) {
73  $hObj->set( $key, $i );
74  }
75  }
76  ];
77  $mObj = null;
78  $benches['MapCacheLRU::set'] = [
79  'setup' => function () use ( &$mObj, $max ) {
80  $mObj = new MapCacheLRU( $max );
81  },
82  'function' => function () use ( &$mObj, &$keys ) {
83  foreach ( $keys as $i => $key ) {
84  $mObj->set( $key, $i );
85  }
86  }
87  ];
88  }
89 
90  $this->bench( $benches );
91  }
92 }
93 
95 require_once RUN_MAINTENANCE_IF_MAIN;
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:317
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:50
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
BenchmarkLruHash\$defaultCount
$defaultCount
Definition: benchmarkLruHash.php:30
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:236
MapCacheLRU
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:37
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
BenchmarkLruHash\__construct
__construct()
Default constructor.
Definition: benchmarkLruHash.php:32
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:40
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:271
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
$keys
$keys
Definition: testCompression.php:67
$maintClass
$maintClass
Definition: benchmarkLruHash.php:94
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
BenchmarkLruHash
Maintenance script that benchmarks HashBagOStuff and MapCacheLRU.
Definition: benchmarkLruHash.php:29
BenchmarkLruHash\execute
execute()
Do the actual work.
Definition: benchmarkLruHash.php:38
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:296