benchmarks: Minor clean up
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 19 Apr 2017 23:06:27 +0000 (16:06 -0700)
committerTim Starling <tstarling@wikimedia.org>
Thu, 20 Apr 2017 04:47:18 +0000 (04:47 +0000)
Change-Id: I446ae1a9d9cdb6b26a6bb62367a432cea082f343

maintenance/benchmarks/Benchmarker.php
maintenance/benchmarks/bench_HTTP_HTTPS.php
maintenance/benchmarks/bench_Wikimedia_base_convert.php
maintenance/benchmarks/bench_delete_truncate.php
maintenance/benchmarks/bench_if_switch.php
maintenance/benchmarks/bench_strtr_str_replace.php
maintenance/benchmarks/bench_utf8_title_check.php
maintenance/benchmarks/bench_wfIsWindows.php

index 5fab082..70dc1f4 100644 (file)
@@ -38,7 +38,7 @@ abstract class Benchmarker extends Maintenance {
 
        public function __construct() {
                parent::__construct();
-               $this->addOption( 'count', "How many times to run a benchmark", false, true );
+               $this->addOption( 'count', 'How many times to run a benchmark', false, true );
        }
 
        public function bench( array $benchs ) {
@@ -68,7 +68,7 @@ abstract class Benchmarker extends Maintenance {
                                'function' => $bench['function'],
                                'arguments' => $bench['args'],
                                'count' => $count,
-                               'delta' => $delta,
+                               'total' => $delta,
                                'average' => $delta / $count,
                        ];
                }
@@ -89,9 +89,9 @@ abstract class Benchmarker extends Maintenance {
                                $res['function'],
                                implode( ', ', $res['arguments'] )
                        );
-                       $ret .= sprintf( "   %6.2fms (%6.2fms each)\n",
-                               $res['delta'] * 1000,
-                               $res['average'] * 1000
+                       $ret .= sprintf( "   %6.2fms (%6.4fms each)\n",
+                               $res['total'] * 1e3,
+                               $res['average'] * 1e3
                        );
                }
 
index 5b64bee..1be50bd 100644 (file)
@@ -42,20 +42,20 @@ class BenchHttpHttps extends Benchmarker {
                        [ 'function' => [ $this, 'getHTTP' ] ],
                        [ 'function' => [ $this, 'getHTTPS' ] ],
                ] );
-               print $this->getFormattedResults();
+               $this->output( $this->getFormattedResults() );
        }
 
-       static function doRequest( $proto ) {
+       private function doRequest( $proto ) {
                Http::get( "$proto://localhost/", [], __METHOD__ );
        }
 
        // bench function 1
-       function getHTTP() {
+       protected function getHTTP() {
                $this->doRequest( 'http' );
        }
 
        // bench function 2
-       function getHTTPS() {
+       protected function getHTTPS() {
                $this->doRequest( 'https' );
        }
 }
index c8a9055..bc83a24 100644 (file)
@@ -65,8 +65,8 @@ class BenchWikimediaBaseConvert extends Benchmarker {
        }
 
        protected static function makeRandomNumber( $base, $length ) {
-               $baseChars = "0123456789abcdefghijklmnopqrstuvwxyz";
-               $res = "";
+               $baseChars = '0123456789abcdefghijklmnopqrstuvwxyz';
+               $res = '';
                for ( $i = 0; $i < $length; $i++ ) {
                        $res .= $baseChars[mt_rand( 0, $base - 1 )];
                }
index 2369d99..042f8bd 100644 (file)
@@ -102,5 +102,5 @@ class BenchmarkDeleteTruncate extends Benchmarker {
        }
 }
 
-$maintClass = "BenchmarkDeleteTruncate";
+$maintClass = 'BenchmarkDeleteTruncate';
 require_once RUN_MAINTENANCE_IF_MAIN;
index 46c9d39..32c3932 100644 (file)
@@ -42,11 +42,11 @@ class BenchIfSwitch extends Benchmarker {
                        [ 'function' => [ $this, 'doElseIf' ] ],
                        [ 'function' => [ $this, 'doSwitch' ] ],
                ] );
-               print $this->getFormattedResults();
+               $this->output( $this->getFormattedResults() );
        }
 
        // bench function 1
-       function doElseIf() {
+       protected function doElseIf() {
                $a = 'z';
                if ( $a == 'a' ) {
                } elseif ( $a == 'b' ) {
@@ -69,7 +69,7 @@ class BenchIfSwitch extends Benchmarker {
        }
 
        // bench function 2
-       function doSwitch() {
+       protected function doSwitch() {
                $a = 'z';
                switch ( $a ) {
                        case 'b':
index 156f8fc..276e666 100644 (file)
@@ -51,22 +51,22 @@ class BenchStrtrStrReplace extends Benchmarker {
                        [ 'function' => [ $this, 'benchstrtr_indirect' ] ],
                        [ 'function' => [ $this, 'benchstr_replace_indirect' ] ],
                ] );
-               print $this->getFormattedResults();
+               $this->output( $this->getFormattedResults() );
        }
 
-       function benchstrtr() {
+       protected function benchstrtr() {
                strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
        }
 
-       function benchstr_replace() {
+       protected function benchstr_replace() {
                str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" );
        }
 
-       function benchstrtr_indirect() {
+       protected function benchstrtr_indirect() {
                bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
        }
 
-       function benchstr_replace_indirect() {
+       protected function benchstr_replace_indirect() {
                bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
        }
 }
index b2f7e96..9ba1623 100644 (file)
@@ -32,6 +32,8 @@ require_once __DIR__ . '/Benchmarker.php';
 class BenchUtf8TitleCheck extends Benchmarker {
        private $data;
 
+       private $isutf8;
+
        public function __construct() {
                parent::__construct();
 
@@ -84,29 +86,27 @@ class BenchUtf8TitleCheck extends Benchmarker {
                        ];
                }
                $this->bench( $benchmarks );
-               print $this->getFormattedResults();
+               $this->output( $this->getFormattedResults() );
        }
 
-       private $isutf8;
-
-       function use_regexp( $s ) {
+       protected function use_regexp( $s ) {
                $this->isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
                        '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
        }
 
-       function use_regexp_non_capturing( $s ) {
+       protected function use_regexp_non_capturing( $s ) {
                // Same as above with a non-capturing subgroup.
                $this->isutf8 = preg_match( '/^(?:[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
                        '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
        }
 
-       function use_regexp_once_only( $s ) {
+       protected function use_regexp_once_only( $s ) {
                // Same as above with a once-only subgroup.
                $this->isutf8 = preg_match( '/^(?>[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
                        '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
        }
 
-       function use_mb_check_encoding( $s ) {
+       protected function use_mb_check_encoding( $s ) {
                $this->isutf8 = mb_check_encoding( $s, 'UTF-8' );
        }
 }
index ac0caf6..f26dbb2 100644 (file)
@@ -45,17 +45,17 @@ class BenchWfIsWindows extends Benchmarker {
                print $this->getFormattedResults();
        }
 
-       static function is_win() {
+       protected static function is_win() {
                return substr( php_uname(), 0, 7 ) == 'Windows';
        }
 
        // bench function 1
-       function wfIsWindows() {
+       protected function wfIsWindows() {
                return self::is_win();
        }
 
        // bench function 2
-       function wfIsWindowsCached() {
+       protected function wfIsWindowsCached() {
                static $isWindows = null;
                if ( $isWindows == null ) {
                        $isWindows = self::is_win();