MediaWiki  REL1_24
bench_wfBaseConvert.php
Go to the documentation of this file.
00001 <?php
00025 require_once __DIR__ . '/Benchmarker.php';
00026 
00032 class BenchWfBaseConvert extends Benchmarker {
00033     public function __construct() {
00034         parent::__construct();
00035         $this->mDescription = "Benchmark for wfBaseConvert.";
00036         $this->addOption( "inbase", "Input base", false, true );
00037         $this->addOption( "outbase", "Output base", false, true );
00038         $this->addOption( "length", "Size in digits to generate for input", false, true );
00039     }
00040 
00041     public function execute() {
00042         $inbase = $this->getOption( "inbase", 36 );
00043         $outbase = $this->getOption( "outbase", 16 );
00044         $length = $this->getOption( "length", 128 );
00045         $number = self::makeRandomNumber( $inbase, $length );
00046 
00047         $this->bench( array(
00048             array(
00049                 'function' => 'wfBaseConvert',
00050                 'args' => array( $number, $inbase, $outbase, 0, true, 'php' )
00051             ),
00052             array(
00053                 'function' => 'wfBaseConvert',
00054                 'args' => array( $number, $inbase, $outbase, 0, true, 'bcmath' )
00055             ),
00056             array(
00057                 'function' => 'wfBaseConvert',
00058                 'args' => array( $number, $inbase, $outbase, 0, true, 'gmp' )
00059             ),
00060         ) );
00061 
00062         $this->output( $this->getFormattedResults() );
00063     }
00064 
00065     protected static function makeRandomNumber( $base, $length ) {
00066         $baseChars = "0123456789abcdefghijklmnopqrstuvwxyz";
00067         $res = "";
00068         for ( $i = 0; $i < $length; $i++ ) {
00069             $res .= $baseChars[mt_rand( 0, $base - 1 )];
00070         }
00071 
00072         return $res;
00073     }
00074 }
00075 
00076 $maintClass = 'BenchWfBaseConvert';
00077 require_once RUN_MAINTENANCE_IF_MAIN;