From 27822f0fa14159dfc71ff0b6e1d994692cf4ed60 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 19 Apr 2017 16:06:27 -0700 Subject: [PATCH] benchmarks: Minor clean up Change-Id: I446ae1a9d9cdb6b26a6bb62367a432cea082f343 --- maintenance/benchmarks/Benchmarker.php | 10 +++++----- maintenance/benchmarks/bench_HTTP_HTTPS.php | 8 ++++---- .../benchmarks/bench_Wikimedia_base_convert.php | 4 ++-- maintenance/benchmarks/bench_delete_truncate.php | 2 +- maintenance/benchmarks/bench_if_switch.php | 6 +++--- maintenance/benchmarks/bench_strtr_str_replace.php | 10 +++++----- maintenance/benchmarks/bench_utf8_title_check.php | 14 +++++++------- maintenance/benchmarks/bench_wfIsWindows.php | 6 +++--- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 5fab082334..70dc1f4494 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -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 ); } diff --git a/maintenance/benchmarks/bench_HTTP_HTTPS.php b/maintenance/benchmarks/bench_HTTP_HTTPS.php index 5b64beeb49..1be50bd438 100644 --- a/maintenance/benchmarks/bench_HTTP_HTTPS.php +++ b/maintenance/benchmarks/bench_HTTP_HTTPS.php @@ -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' ); } } diff --git a/maintenance/benchmarks/bench_Wikimedia_base_convert.php b/maintenance/benchmarks/bench_Wikimedia_base_convert.php index c8a9055e42..bc83a24f14 100644 --- a/maintenance/benchmarks/bench_Wikimedia_base_convert.php +++ b/maintenance/benchmarks/bench_Wikimedia_base_convert.php @@ -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 )]; } diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php index 2369d993ea..042f8bde21 100644 --- a/maintenance/benchmarks/bench_delete_truncate.php +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -102,5 +102,5 @@ class BenchmarkDeleteTruncate extends Benchmarker { } } -$maintClass = "BenchmarkDeleteTruncate"; +$maintClass = 'BenchmarkDeleteTruncate'; require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_if_switch.php b/maintenance/benchmarks/bench_if_switch.php index 46c9d39bc7..32c3932266 100644 --- a/maintenance/benchmarks/bench_if_switch.php +++ b/maintenance/benchmarks/bench_if_switch.php @@ -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': diff --git a/maintenance/benchmarks/bench_strtr_str_replace.php b/maintenance/benchmarks/bench_strtr_str_replace.php index 156f8fcfe0..276e666f22 100644 --- a/maintenance/benchmarks/bench_strtr_str_replace.php +++ b/maintenance/benchmarks/bench_strtr_str_replace.php @@ -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]]" ); } } diff --git a/maintenance/benchmarks/bench_utf8_title_check.php b/maintenance/benchmarks/bench_utf8_title_check.php index b2f7e96138..9ba162307b 100644 --- a/maintenance/benchmarks/bench_utf8_title_check.php +++ b/maintenance/benchmarks/bench_utf8_title_check.php @@ -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' ); } } diff --git a/maintenance/benchmarks/bench_wfIsWindows.php b/maintenance/benchmarks/bench_wfIsWindows.php index ac0caf6096..f26dbb276c 100644 --- a/maintenance/benchmarks/bench_wfIsWindows.php +++ b/maintenance/benchmarks/bench_wfIsWindows.php @@ -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(); -- 2.20.1