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