22 require_once __DIR__ .
'/../includes/Benchmarker.php';
33 parent::__construct();
34 $this->
addDescription(
'Benchmarks HashBagOStuff and MapCacheLRU.' );
35 $this->
addOption(
'method',
'One of "construct" or "set". Default: [All]',
false,
true );
46 $keys = array_merge( $exampleKeys, array_reverse( $exampleKeys ) );
51 if ( !$method || $method ===
'construct' ) {
52 $benches[
'HashBagOStuff::__construct'] = [
53 'function' =>
static function () use ( $max ) {
57 $benches[
'MapCacheLRU::__construct'] = [
58 'function' =>
static function () use ( $max ) {
64 if ( !$method || $method ===
'set' ) {
66 '@phan-var BagOStuff $hObj';
67 $benches[
'HashBagOStuff::set'] = [
68 'setup' =>
static function () use ( &$hObj, $max ) {
71 'function' =>
static function () use ( &$hObj, $keys ) {
72 foreach ( $keys as $i => $key ) {
73 $hObj->set( $key, $i );
78 '@phan-var MapCacheLRU $mObj';
79 $benches[
'MapCacheLRU::set'] = [
80 'setup' =>
static function () use ( &$mObj, $max ) {
83 'function' =>
static function () use ( &$mObj, $keys ) {
84 foreach ( $keys as $i => $key ) {
85 $mObj->set( $key, $i );
91 if ( !$method || $method ===
'get' ) {
93 '@phan-var BagOStuff $hObj';
94 $benches[
'HashBagOStuff::get'] = [
95 'setup' =>
static function () use ( &$hObj, $max, $keys ) {
97 foreach ( $keys as $i => $key ) {
98 $hObj->set( $key, $i );
101 'function' =>
static function () use ( &$hObj, $keys ) {
102 foreach ( $keys as $key ) {
108 '@phan-var MapCacheLRU $mObj';
109 $benches[
'MapCacheLRU::get'] = [
110 'setup' =>
static function () use ( &$mObj, $max, $keys ) {
112 foreach ( $keys as $i => $key ) {
113 $mObj->set( $key, $i );
116 'function' =>
static function () use ( &$mObj, $keys ) {
117 foreach ( $keys as $key ) {
124 $this->
bench( $benches );
129 require_once RUN_MAINTENANCE_IF_MAIN;
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Maintenance script that benchmarks HashBagOStuff and MapCacheLRU.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
Simple store for keeping values in an associative array for the current process.
addDescription( $text)
Set the description text.
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.
Store key-value entries in a size-limited in-memory LRU cache.