diff options
Diffstat (limited to 'maintenance/benchmarks')
-rw-r--r-- | maintenance/benchmarks/Benchmarker.php | 21 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_HTTP_HTTPS.php | 7 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_delete_truncate.php | 9 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_if_switch.php | 89 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_strtr_str_replace.php | 11 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_utf8_title_check.php | 29 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_wfBaseConvert.php | 12 | ||||
-rw-r--r-- | maintenance/benchmarks/bench_wfIsWindows.php | 12 | ||||
-rw-r--r-- | maintenance/benchmarks/benchmarkHooks.php | 8 | ||||
-rw-r--r-- | maintenance/benchmarks/benchmarkParse.php | 174 | ||||
-rw-r--r-- | maintenance/benchmarks/benchmarkPurge.php | 11 |
11 files changed, 286 insertions, 97 deletions
diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index dd558f32..3f8a8990 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -46,38 +46,38 @@ abstract class Benchmarker extends Maintenance { $bench_number = 0; $count = $this->getOption( 'count', 100 ); - foreach( $benchs as $bench ) { + 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'] ) ) { + if ( is_array( $bench['function'] ) ) { $ret = get_class( $bench['function'][0] ) . '->' . $bench['function'][1]; $bench['function'] = $ret; } $this->results[$bench_number] = array( - 'function' => $bench['function'], + 'function' => $bench['function'], 'arguments' => $bench['args'], - 'count' => $count, - 'delta' => $delta, - 'average' => $delta / $count, - ); + 'count' => $count, + 'delta' => $delta, + 'average' => $delta / $count, + ); } } public function getFormattedResults() { $ret = ''; - foreach( $this->results as $res ) { + foreach ( $this->results as $res ) { // show function with args $ret .= sprintf( "%s times: function %s(%s) :\n", $res['count'], @@ -89,6 +89,7 @@ abstract class Benchmarker extends Maintenance { $res['average'] * 1000 ); } + return $ret; } } diff --git a/maintenance/benchmarks/bench_HTTP_HTTPS.php b/maintenance/benchmarks/bench_HTTP_HTTPS.php index 6f800fb3..bb7499b7 100644 --- a/maintenance/benchmarks/bench_HTTP_HTTPS.php +++ b/maintenance/benchmarks/bench_HTTP_HTTPS.php @@ -31,8 +31,7 @@ require_once __DIR__ . '/Benchmarker.php'; * * @ingroup Benchmark */ -class bench_HTTP_HTTPS extends Benchmarker { - +class BenchHttpHttps extends Benchmarker { public function __construct() { parent::__construct(); $this->mDescription = "Benchmark HTTP request vs HTTPS request."; @@ -42,7 +41,7 @@ class bench_HTTP_HTTPS extends Benchmarker { $this->bench( array( array( 'function' => array( $this, 'getHTTP' ) ), array( 'function' => array( $this, 'getHTTPS' ) ), - )); + ) ); print $this->getFormattedResults(); } @@ -61,5 +60,5 @@ class bench_HTTP_HTTPS extends Benchmarker { } } -$maintClass = 'bench_HTTP_HTTPS'; +$maintClass = 'BenchHttpHttps'; require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php index 3eff534b..8ae4f030 100644 --- a/maintenance/benchmarks/bench_delete_truncate.php +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -29,7 +29,6 @@ require_once __DIR__ . '/Benchmarker.php'; * @ingroup Benchmark */ class BenchmarkDeleteTruncate extends Benchmarker { - public function __construct() { parent::__construct(); $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE."; @@ -70,20 +69,20 @@ class BenchmarkDeleteTruncate extends Benchmarker { } /** - * @param $dbw DatabaseBase + * @param DatabaseBase $dbw * @return void */ private function insertData( $dbw ) { $range = range( 0, 1024 ); $data = array(); - foreach( $range as $r ) { + foreach ( $range as $r ) { $data[] = array( 'text' => $r ); } $dbw->insert( 'test', $data, __METHOD__ ); } /** - * @param $dbw DatabaseBase + * @param DatabaseBase $dbw * @return void */ private function delete( $dbw ) { @@ -91,7 +90,7 @@ class BenchmarkDeleteTruncate extends Benchmarker { } /** - * @param $dbw DatabaseBase + * @param DatabaseBase $dbw * @return void */ private function truncate( $dbw ) { diff --git a/maintenance/benchmarks/bench_if_switch.php b/maintenance/benchmarks/bench_if_switch.php index 80fd9623..698a0f0a 100644 --- a/maintenance/benchmarks/bench_if_switch.php +++ b/maintenance/benchmarks/bench_if_switch.php @@ -31,8 +31,7 @@ require_once __DIR__ . '/Benchmarker.php'; * * @ingroup Maintenance */ -class bench_if_switch extends Benchmarker { - +class BenchIfSwitch extends Benchmarker { public function __construct() { parent::__construct(); $this->mDescription = "Benchmark if elseif... versus switch case."; @@ -42,55 +41,71 @@ class bench_if_switch extends Benchmarker { $this->bench( array( array( 'function' => array( $this, 'doElseIf' ) ), array( 'function' => array( $this, 'doSwitch' ) ), - )); + ) ); print $this->getFormattedResults(); } // bench function 1 function doElseIf() { $a = 'z'; - if( $a == 'a') {} - elseif( $a == 'b') {} - elseif( $a == 'c') {} - elseif( $a == 'd') {} - elseif( $a == 'e') {} - elseif( $a == 'f') {} - elseif( $a == 'g') {} - elseif( $a == 'h') {} - elseif( $a == 'i') {} - elseif( $a == 'j') {} - elseif( $a == 'k') {} - elseif( $a == 'l') {} - elseif( $a == 'm') {} - elseif( $a == 'n') {} - elseif( $a == 'o') {} - elseif( $a == 'p') {} - else {} + if ( $a == 'a' ) { + } elseif ( $a == 'b' ) { + } elseif ( $a == 'c' ) { + } elseif ( $a == 'd' ) { + } elseif ( $a == 'e' ) { + } elseif ( $a == 'f' ) { + } elseif ( $a == 'g' ) { + } elseif ( $a == 'h' ) { + } elseif ( $a == 'i' ) { + } elseif ( $a == 'j' ) { + } elseif ( $a == 'k' ) { + } elseif ( $a == 'l' ) { + } elseif ( $a == 'm' ) { + } elseif ( $a == 'n' ) { + } elseif ( $a == 'o' ) { + } elseif ( $a == 'p' ) { + } else { + } } // bench function 2 function doSwitch() { $a = 'z'; - switch( $a ) { - case 'b': break; - case 'c': break; - case 'd': break; - case 'e': break; - case 'f': break; - case 'g': break; - case 'h': break; - case 'i': break; - case 'j': break; - case 'k': break; - case 'l': break; - case 'm': break; - case 'n': break; - case 'o': break; - case 'p': break; + switch ( $a ) { + case 'b': + break; + case 'c': + break; + case 'd': + break; + case 'e': + break; + case 'f': + break; + case 'g': + break; + case 'h': + break; + case 'i': + break; + case 'j': + break; + case 'k': + break; + case 'l': + break; + case 'm': + break; + case 'n': + break; + case 'o': + break; + case 'p': + break; default: } } } -$maintClass = 'bench_if_switch'; +$maintClass = 'BenchIfSwitch'; 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 bd21b186..44c8e032 100644 --- a/maintenance/benchmarks/bench_strtr_str_replace.php +++ b/maintenance/benchmarks/bench_strtr_str_replace.php @@ -38,8 +38,7 @@ function bfNormalizeTitleStrReplace( $str ) { * * @ingroup Benchmark */ -class bench_strtr_str_replace extends Benchmarker { - +class BenchStrtrStrReplace extends Benchmarker { public function __construct() { parent::__construct(); $this->mDescription = "Benchmark for strtr() vs str_replace()."; @@ -51,7 +50,7 @@ class bench_strtr_str_replace extends Benchmarker { array( 'function' => array( $this, 'benchstr_replace' ) ), array( 'function' => array( $this, 'benchstrtr_indirect' ) ), array( 'function' => array( $this, 'benchstr_replace_indirect' ) ), - )); + ) ); print $this->getFormattedResults(); } @@ -60,10 +59,9 @@ class bench_strtr_str_replace extends Benchmarker { } function benchstr_replace() { - str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]"); + str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" ); } - function benchstrtr_indirect() { bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" ); } @@ -71,8 +69,7 @@ class bench_strtr_str_replace extends Benchmarker { function benchstr_replace_indirect() { bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" ); } - } -$maintClass = 'bench_strtr_str_replace'; +$maintClass = 'BenchStrtrStrReplace'; 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 078293eb..b742f666 100644 --- a/maintenance/benchmarks/bench_utf8_title_check.php +++ b/maintenance/benchmarks/bench_utf8_title_check.php @@ -29,8 +29,7 @@ require_once __DIR__ . '/Benchmarker.php'; * * @ingroup Benchmark */ -class bench_utf8_title_check extends Benchmarker { - +class BenchUtf8TitleCheck extends Benchmarker { private $canRun; private $data; @@ -38,6 +37,7 @@ class bench_utf8_title_check extends Benchmarker { public function __construct() { parent::__construct(); + // @codingStandardsIgnoreStart Ignore long line warnings. $this->data = array( "", "United States of America", // 7bit ASCII @@ -59,11 +59,13 @@ class bench_utf8_title_check extends Benchmarker { . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C" . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis" ); + // @codingStandardsIgnoreEnd - $this->canRun = function_exists ( 'mb_check_encoding' ); + $this->canRun = function_exists( 'mb_check_encoding' ); if ( $this->canRun ) { - $this->mDescription = "Benchmark for using a regexp vs. mb_check_encoding to check for UTF-8 encoding."; + $this->mDescription = "Benchmark for using a regexp vs. mb_check_encoding " . + "to check for UTF-8 encoding."; mb_internal_encoding( 'UTF-8' ); } else { $this->mDescription = "CANNOT RUN benchmark using mb_check_encoding: function not available."; @@ -75,22 +77,22 @@ class bench_utf8_title_check extends Benchmarker { return; } $benchmarks = array(); - foreach ($this->data as $val) { + foreach ( $this->data as $val ) { $benchmarks[] = array( 'function' => array( $this, 'use_regexp' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); $benchmarks[] = array( 'function' => array( $this, 'use_regexp_non_capturing' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); $benchmarks[] = array( 'function' => array( $this, 'use_regexp_once_only' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); $benchmarks[] = array( 'function' => array( $this, 'use_mb_check_encoding' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); } $this->bench( $benchmarks ); @@ -101,26 +103,25 @@ class bench_utf8_title_check extends Benchmarker { 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 ); + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); } 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 ); + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); } 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 ); + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); } function use_mb_check_encoding( $s ) { $this->isutf8 = mb_check_encoding( $s, 'UTF-8' ); } - } -$maintClass = 'bench_utf8_title_check'; +$maintClass = 'BenchUtf8TitleCheck'; require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_wfBaseConvert.php b/maintenance/benchmarks/bench_wfBaseConvert.php index f8a21562..b4be12bc 100644 --- a/maintenance/benchmarks/bench_wfBaseConvert.php +++ b/maintenance/benchmarks/bench_wfBaseConvert.php @@ -29,8 +29,7 @@ require_once __DIR__ . '/Benchmarker.php'; * * @ingroup Benchmark */ -class bench_wfBaseConvert extends Benchmarker { - +class BenchWfBaseConvert extends Benchmarker { public function __construct() { parent::__construct(); $this->mDescription = "Benchmark for wfBaseConvert."; @@ -58,7 +57,7 @@ class bench_wfBaseConvert extends Benchmarker { 'function' => 'wfBaseConvert', 'args' => array( $number, $inbase, $outbase, 0, true, 'gmp' ) ), - )); + ) ); $this->output( $this->getFormattedResults() ); } @@ -66,12 +65,13 @@ class bench_wfBaseConvert extends Benchmarker { protected static function makeRandomNumber( $base, $length ) { $baseChars = "0123456789abcdefghijklmnopqrstuvwxyz"; $res = ""; - for( $i = 0; $i < $length; $i++ ) { - $res .= $baseChars[mt_rand(0, $base - 1)]; + for ( $i = 0; $i < $length; $i++ ) { + $res .= $baseChars[mt_rand( 0, $base - 1 )]; } + return $res; } } -$maintClass = 'bench_wfBaseConvert'; +$maintClass = 'BenchWfBaseConvert'; require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/bench_wfIsWindows.php b/maintenance/benchmarks/bench_wfIsWindows.php index 1cd2016b..8446694b 100644 --- a/maintenance/benchmarks/bench_wfIsWindows.php +++ b/maintenance/benchmarks/bench_wfIsWindows.php @@ -31,8 +31,7 @@ require_once __DIR__ . '/Benchmarker.php'; * * @ingroup Benchmark */ -class bench_wfIsWindows extends Benchmarker { - +class BenchWfIsWindows extends Benchmarker { public function __construct() { parent::__construct(); $this->mDescription = "Benchmark for wfIsWindows."; @@ -42,12 +41,12 @@ class bench_wfIsWindows extends Benchmarker { $this->bench( array( array( 'function' => array( $this, 'wfIsWindows' ) ), array( 'function' => array( $this, 'wfIsWindowsCached' ) ), - )); + ) ); print $this->getFormattedResults(); } static function is_win() { - return substr( php_uname(), 0, 7 ) == 'Windows' ; + return substr( php_uname(), 0, 7 ) == 'Windows'; } // bench function 1 @@ -58,12 +57,13 @@ class bench_wfIsWindows extends Benchmarker { // bench function 2 function wfIsWindowsCached() { static $isWindows = null; - if( $isWindows == null ) { + if ( $isWindows == null ) { $isWindows = self::is_win(); } + return $isWindows; } } -$maintClass = 'bench_wfIsWindows'; +$maintClass = 'BenchWfIsWindows'; require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php index 3f5d6db0..fb25b9d9 100644 --- a/maintenance/benchmarks/benchmarkHooks.php +++ b/maintenance/benchmarks/benchmarkHooks.php @@ -29,7 +29,6 @@ require_once __DIR__ . '/Benchmarker.php'; * @ingroup Benchmark */ class BenchmarkHooks extends Benchmarker { - public function __construct() { parent::__construct(); $this->mDescription = 'Benchmark MediaWiki Hooks.'; @@ -46,13 +45,13 @@ class BenchmarkHooks extends Benchmarker { $time = $this->benchHooks(); $this->output( 'Loaded (one) hook: ' . $time . "\n" ); - for( $i = 0; $i < 9; $i++ ) { + for ( $i = 0; $i < 9; $i++ ) { $wgHooks['Test'][] = array( $this, 'test' ); } $time = $this->benchHooks(); $this->output( 'Loaded (ten) hook: ' . $time . "\n" ); - for( $i = 0; $i < 90; $i++ ) { + for ( $i = 0; $i < 90; $i++ ) { $wgHooks['Test'][] = array( $this, 'test' ); } $time = $this->benchHooks(); @@ -61,7 +60,7 @@ class BenchmarkHooks extends Benchmarker { } /** - * @param $trials int + * @param int $trials * @return string */ private function benchHooks( $trials = 10 ) { @@ -71,6 +70,7 @@ class BenchmarkHooks extends Benchmarker { } $delta = microtime( true ) - $start; $pertrial = $delta / $trials; + return sprintf( "Took %6.3fms", $pertrial * 1000 ); } diff --git a/maintenance/benchmarks/benchmarkParse.php b/maintenance/benchmarks/benchmarkParse.php new file mode 100644 index 00000000..ce38dad6 --- /dev/null +++ b/maintenance/benchmarks/benchmarkParse.php @@ -0,0 +1,174 @@ +<?php +/** + * Benchmark script for parse operations + * + * 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 + * @author Tim Starling <tstarling@wikimedia.org> + * @ingroup Benchmark + */ + +require __DIR__ . '/../Maintenance.php'; + +/** + * Maintenance script to benchmark how long it takes to parse a given title at an optionally + * specified timestamp + * + * @since 1.23 + */ +class BenchmarkParse extends Maintenance { + /** @var string MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS) */ + private $templateTimestamp = null; + + /** @var array Cache that maps a Title DB key to revision ID for the requested timestamp */ + private $idCache = array(); + + function __construct() { + parent::__construct(); + $this->addDescription( 'Benchmark parse operation' ); + $this->addArg( 'title', 'The name of the page to parse' ); + $this->addOption( 'warmup', 'Repeat the parse operation this number of times to warm the cache', + false, true ); + $this->addOption( 'loops', 'Number of times to repeat parse operation post-warmup', + false, true ); + $this->addOption( 'page-time', + 'Use the version of the page which was current at the given time', + false, true ); + $this->addOption( 'tpl-time', + 'Use templates which were current at the given time (except that moves and ' . + 'deletes are not handled properly)', + false, true ); + } + + function execute() { + if ( $this->hasOption( 'tpl-time' ) ) { + $this->templateTimestamp = wfTimestamp( TS_MW, strtotime( $this->getOption( 'tpl-time' ) ) ); + Hooks::register( 'BeforeParserFetchTemplateAndtitle', array( $this, 'onFetchTemplate' ) ); + } + + $title = Title::newFromText( $this->getArg() ); + if ( !$title ) { + $this->error( "Invalid title" ); + exit( 1 ); + } + + if ( $this->hasOption( 'page-time' ) ) { + $pageTimestamp = wfTimestamp( TS_MW, strtotime( $this->getOption( 'page-time' ) ) ); + $id = $this->getRevIdForTime( $title, $pageTimestamp ); + if ( !$id ) { + $this->error( "The page did not exist at that time" ); + exit( 1 ); + } + + $revision = Revision::newFromId( $id ); + } else { + $revision = Revision::newFromTitle( $title ); + } + + if ( !$revision ) { + $this->error( "Unable to load revision, incorrect title?" ); + exit( 1 ); + } + + $warmup = $this->getOption( 'warmup', 1 ); + for ( $i = 0; $i < $warmup; $i++ ) { + $this->runParser( $revision ); + } + + $loops = $this->getOption( 'loops', 1 ); + if ( $loops < 1 ) { + $this->error( 'Invalid number of loops specified', true ); + } + $startUsage = getrusage(); + $startTime = microtime( true ); + for ( $i = 0; $i < $loops; $i++ ) { + $this->runParser( $revision ); + } + $endUsage = getrusage(); + $endTime = microtime( true ); + + printf( "CPU time = %.3f s, wall clock time = %.3f s\n", + // CPU time + ( $endUsage['ru_utime.tv_sec'] + $endUsage['ru_utime.tv_usec'] * 1e-6 + - $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1e-6 ) / $loops, + // Wall clock time + ( $endTime - $startTime ) / $loops + ); + } + + /** + * Fetch the ID of the revision of a Title that occurred + * + * @param Title $title + * @param string $timestamp + * @return bool|string Revision ID, or false if not found or error + */ + function getRevIdForTime( Title $title, $timestamp ) { + $dbr = wfGetDB( DB_SLAVE ); + + $id = $dbr->selectField( + array( 'revision', 'page' ), + 'rev_id', + array( + 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDBkey(), + 'rev_timestamp <= ' . $dbr->addQuotes( $timestamp ) + ), + __METHOD__, + array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 1 ), + array( 'revision' => array( 'INNER JOIN', 'rev_page=page_id' ) ) + ); + + return $id; + } + + /** + * Parse the text from a given Revision + * + * @param Revision $revision + */ + function runParser( Revision $revision ) { + $content = $revision->getContent(); + $content->getParserOutput( $revision->getTitle(), $revision->getId() ); + } + + /** + * Hook into the parser's revision ID fetcher. Make sure that the parser only + * uses revisions around the specified timestamp. + * + * @param Parser $parser + * @param Title $title + * @param bool &$skip + * @param string|bool &$id + * @return bool + */ + function onFetchTemplate( Parser $parser, Title $title, &$skip, &$id ) { + $pdbk = $title->getPrefixedDBkey(); + if ( !isset( $this->idCache[$pdbk] ) ) { + $proposedId = $this->getRevIdForTime( $title, $this->templateTimestamp ); + $this->idCache[$pdbk] = $proposedId; + } + if ( $this->idCache[$pdbk] !== false ) { + $id = $this->idCache[$pdbk]; + } + + return true; + } +} + +$maintClass = 'BenchmarkParse'; +require RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/benchmarkPurge.php b/maintenance/benchmarks/benchmarkPurge.php index fd863d52..42c1eb78 100644 --- a/maintenance/benchmarks/benchmarkPurge.php +++ b/maintenance/benchmarks/benchmarkPurge.php @@ -29,7 +29,6 @@ require_once __DIR__ . '/Benchmarker.php'; * @ingroup Benchmark */ class BenchmarkPurge extends Benchmarker { - public function __construct() { parent::__construct(); $this->mDescription = "Benchmark the Squid purge functions."; @@ -57,8 +56,8 @@ class BenchmarkPurge extends Benchmarker { /** * Run a bunch of URLs through SquidUpdate::purge() * to benchmark Squid response times. - * @param $urls array A bunch of URLs to purge - * @param $trials int How many times to run the test? + * @param array $urls A bunch of URLs to purge + * @param int $trials How many times to run the test? * @return string */ private function benchSquid( $urls, $trials = 1 ) { @@ -69,13 +68,14 @@ class BenchmarkPurge extends Benchmarker { $delta = microtime( true ) - $start; $pertrial = $delta / $trials; $pertitle = $pertrial / count( $urls ); + return sprintf( "%4d titles in %6.2fms (%6.2fms each)", count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 ); } /** * Get an array of randomUrl()'s. - * @param $length int How many urls to add to the array + * @param int $length How many urls to add to the array * @return array */ private function randomUrlList( $length ) { @@ -83,6 +83,7 @@ class BenchmarkPurge extends Benchmarker { for ( $i = 0; $i < $length; $i++ ) { $list[] = $this->randomUrl(); } + return $list; } @@ -93,6 +94,7 @@ class BenchmarkPurge extends Benchmarker { */ private function randomUrl() { global $wgServer, $wgArticlePath; + return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath ); } @@ -107,6 +109,7 @@ class BenchmarkPurge extends Benchmarker { for ( $i = 0; $i < $length; $i++ ) { $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) ); } + return ucfirst( $str ); } } |