diff options
Diffstat (limited to 'maintenance/benchmarks')
-rw-r--r-- | maintenance/benchmarks/Benchmarker.php | 12 | ||||
-rw-r--r-- | maintenance/benchmarks/README | 7 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_HTTP_HTTPS.php | 4 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_delete_truncate.php | 4 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_if_switch.php | 4 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_strtr_str_replace.php | 8 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_utf8_title_check.php | 6 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_wfBaseConvert.php | 77 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_wfIsWindows.php | 4 | ||||
-rw-r--r-- | maintenance/benchmarks/benchmarkHooks.php | 4 | ||||
-rw-r--r-- | maintenance/benchmarks/benchmarkPurge.php | 4 |
11 files changed, 109 insertions, 25 deletions
diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index c198e0ff..dd558f32 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -27,7 +27,7 @@ * @ingroup Benchmark */ -require_once( __DIR__ . '/../Maintenance.php' ); +require_once __DIR__ . '/../Maintenance.php'; /** * Base class for benchmark scripts. @@ -48,20 +48,20 @@ abstract class Benchmarker extends Maintenance { foreach( $benchs as $bench ) { // handle empty args - if(!array_key_exists( 'args', $bench )) { + if( !array_key_exists( 'args', $bench ) ) { $bench['args'] = array(); } $bench_number++; $start = microtime( true ); - for( $i=0; $i<$count; $i++ ) { + for( $i = 0; $i < $count; $i++ ) { call_user_func_array( $bench['function'], $bench['args'] ); } $delta = microtime( true ) - $start; // function passed as a callback if( is_array( $bench['function'] ) ) { - $ret = get_class( $bench['function'][0] ). '->' . $bench['function'][1]; + $ret = get_class( $bench['function'][0] ) . '->' . $bench['function'][1]; $bench['function'] = $ret; } @@ -75,7 +75,7 @@ abstract class Benchmarker extends Maintenance { } } - public function getFormattedResults( ) { + public function getFormattedResults() { $ret = ''; foreach( $this->results as $res ) { // show function with args @@ -85,7 +85,7 @@ abstract class Benchmarker extends Maintenance { join( ', ', $res['arguments'] ) ); $ret .= sprintf( " %6.2fms (%6.2fms each)\n", - $res['delta'] * 1000, + $res['delta'] * 1000, $res['average'] * 1000 ); } diff --git a/maintenance/benchmarks/README b/maintenance/benchmarks/README new file mode 100644 index 00000000..c021abd2 --- /dev/null +++ b/maintenance/benchmarks/README @@ -0,0 +1,7 @@ +This directory hold several benchmarking scripts used as a proof of speed +or to track PHP performances over time. + +To get somehow accurate result, you might want to bound the PHP process +to a specific CPU with `taskset` and raise its priority with `nice`. Example: + + $ taskset 1 nice -n-10 php bench_wfIsWindows.php diff --git a/maintenance/benchmarks/bench_HTTP_HTTPS.php b/maintenance/benchmarks/bench_HTTP_HTTPS.php index fa76ae22..6f800fb3 100644 --- a/maintenance/benchmarks/bench_HTTP_HTTPS.php +++ b/maintenance/benchmarks/bench_HTTP_HTTPS.php @@ -24,7 +24,7 @@ * @author Platonides */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * Maintenance script that benchmarks HTTP request vs HTTPS request. @@ -62,4 +62,4 @@ class bench_HTTP_HTTPS extends Benchmarker { } $maintClass = 'bench_HTTP_HTTPS'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php index d9741496..3eff534b 100644 --- a/maintenance/benchmarks/bench_delete_truncate.php +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -21,7 +21,7 @@ * @ingroup Benchmark */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * Maintenance script that benchmarks SQL DELETE vs SQL TRUNCATE. @@ -101,4 +101,4 @@ class BenchmarkDeleteTruncate extends Benchmarker { } $maintClass = "BenchmarkDeleteTruncate"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_if_switch.php b/maintenance/benchmarks/bench_if_switch.php index 1f590d4d..80fd9623 100644 --- a/maintenance/benchmarks/bench_if_switch.php +++ b/maintenance/benchmarks/bench_if_switch.php @@ -24,7 +24,7 @@ * @author Platonides */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * Maintenance script that benchmark if elseif... versus switch case. @@ -93,4 +93,4 @@ class bench_if_switch extends Benchmarker { } $maintClass = 'bench_if_switch'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_strtr_str_replace.php b/maintenance/benchmarks/bench_strtr_str_replace.php index 9fa7c8e3..bd21b186 100644 --- a/maintenance/benchmarks/bench_strtr_str_replace.php +++ b/maintenance/benchmarks/bench_strtr_str_replace.php @@ -23,14 +23,14 @@ * @ingroup Benchmark */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; function bfNormalizeTitleStrTr( $str ) { - return strtr( $str, '_', ' ' ); + return strtr( $str, '_', ' ' ); } function bfNormalizeTitleStrReplace( $str ) { - return str_replace( '_', ' ', $str ); + return str_replace( '_', ' ', $str ); } /** @@ -75,4 +75,4 @@ class bench_strtr_str_replace extends Benchmarker { } $maintClass = 'bench_strtr_str_replace'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_utf8_title_check.php b/maintenance/benchmarks/bench_utf8_title_check.php index f5987800..078293eb 100644 --- a/maintenance/benchmarks/bench_utf8_title_check.php +++ b/maintenance/benchmarks/bench_utf8_title_check.php @@ -21,7 +21,7 @@ * @ingroup Benchmark */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * This little benchmark executes the regexp used in Language->checkTitleEncoding() @@ -38,7 +38,7 @@ class bench_utf8_title_check extends Benchmarker { public function __construct() { parent::__construct(); - $this->data = array ( + $this->data = array( "", "United States of America", // 7bit ASCII "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e", @@ -123,4 +123,4 @@ class bench_utf8_title_check extends Benchmarker { } $maintClass = 'bench_utf8_title_check'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_wfBaseConvert.php b/maintenance/benchmarks/bench_wfBaseConvert.php new file mode 100644 index 00000000..f8a21562 --- /dev/null +++ b/maintenance/benchmarks/bench_wfBaseConvert.php @@ -0,0 +1,77 @@ +<?php +/** + * Benchmark for wfBaseConvert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Benchmark + * @author Tyler Romeo + */ + +require_once __DIR__ . '/Benchmarker.php'; + +/** + * Maintenance script that benchmarks wfBaseConvert(). + * + * @ingroup Benchmark + */ +class bench_wfBaseConvert extends Benchmarker { + + public function __construct() { + parent::__construct(); + $this->mDescription = "Benchmark for wfBaseConvert."; + $this->addOption( "inbase", "Input base", false, true ); + $this->addOption( "outbase", "Output base", false, true ); + $this->addOption( "length", "Size in digits to generate for input", false, true ); + } + + public function execute() { + $inbase = $this->getOption( "inbase", 36 ); + $outbase = $this->getOption( "outbase", 16 ); + $length = $this->getOption( "length", 128 ); + $number = self::makeRandomNumber( $inbase, $length ); + + $this->bench( array( + array( + 'function' => 'wfBaseConvert', + 'args' => array( $number, $inbase, $outbase, 0, true, 'php' ) + ), + array( + 'function' => 'wfBaseConvert', + 'args' => array( $number, $inbase, $outbase, 0, true, 'bcmath' ) + ), + array( + 'function' => 'wfBaseConvert', + 'args' => array( $number, $inbase, $outbase, 0, true, 'gmp' ) + ), + )); + + $this->output( $this->getFormattedResults() ); + } + + protected static function makeRandomNumber( $base, $length ) { + $baseChars = "0123456789abcdefghijklmnopqrstuvwxyz"; + $res = ""; + for( $i = 0; $i < $length; $i++ ) { + $res .= $baseChars[mt_rand(0, $base - 1)]; + } + return $res; + } +} + +$maintClass = 'bench_wfBaseConvert'; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_wfIsWindows.php b/maintenance/benchmarks/bench_wfIsWindows.php index 85439827..1cd2016b 100644 --- a/maintenance/benchmarks/bench_wfIsWindows.php +++ b/maintenance/benchmarks/bench_wfIsWindows.php @@ -24,7 +24,7 @@ * @author Platonides */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * Maintenance script that benchmarks wfIsWindows(). @@ -66,4 +66,4 @@ class bench_wfIsWindows extends Benchmarker { } $maintClass = 'bench_wfIsWindows'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php index fdb016f4..3f5d6db0 100644 --- a/maintenance/benchmarks/benchmarkHooks.php +++ b/maintenance/benchmarks/benchmarkHooks.php @@ -21,7 +21,7 @@ * @ingroup Benchmark */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * Maintenance script that benchmarks %MediaWiki hooks. @@ -84,4 +84,4 @@ class BenchmarkHooks extends Benchmarker { } $maintClass = 'BenchmarkHooks'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/benchmarkPurge.php b/maintenance/benchmarks/benchmarkPurge.php index ec686b2a..fd863d52 100644 --- a/maintenance/benchmarks/benchmarkPurge.php +++ b/maintenance/benchmarks/benchmarkPurge.php @@ -21,7 +21,7 @@ * @ingroup Benchmark */ -require_once( __DIR__ . '/Benchmarker.php' ); +require_once __DIR__ . '/Benchmarker.php'; /** * Maintenance script that benchmarks Squid purge. @@ -112,4 +112,4 @@ class BenchmarkPurge extends Benchmarker { } $maintClass = "BenchmarkPurge"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; |