From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- maintenance/benchmarks/Benchmarker.php | 23 ++++- maintenance/benchmarks/bench_HTTP_HTTPS.php | 21 +++- maintenance/benchmarks/bench_delete_truncate.php | 78 +++++++++++++++ maintenance/benchmarks/bench_if_switch.php | 88 +++++++++++++++++ maintenance/benchmarks/bench_strtr_str_replace.php | 50 ++++++++++ maintenance/benchmarks/bench_wfIsWindows.php | 21 +++- maintenance/benchmarks/benchmarkPurge.php | 106 +++++++++++++++++++++ 7 files changed, 381 insertions(+), 6 deletions(-) create mode 100644 maintenance/benchmarks/bench_delete_truncate.php create mode 100644 maintenance/benchmarks/bench_if_switch.php create mode 100644 maintenance/benchmarks/bench_strtr_str_replace.php create mode 100644 maintenance/benchmarks/benchmarkPurge.php (limited to 'maintenance/benchmarks') diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 66789ea4..57fb8759 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -1,14 +1,29 @@ mDescription = "Benchmark HTTP request vs HTTPS request."; } public function execute() { diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php new file mode 100644 index 00000000..9fe9bea9 --- /dev/null +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -0,0 +1,78 @@ +mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE."; + } + + public function execute() { + $dbw = wfGetDB( DB_MASTER ); + + $test = $dbw->tableName( 'test' ); + $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test ( + test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, + text varbinary(255) NOT NULL +);" ); + + $this->insertData( $dbw ); + + $start = wfTime(); + + $this->delete( $dbw ); + + $end = wfTime(); + + echo "Delete: " . $end - $start; + echo "\r\n"; + + $this->insertData( $dbw ); + + $start = wfTime(); + + $this->truncate( $dbw ); + + $end = wfTime(); + + echo "Truncate: " . $end - $start; + echo "\r\n"; + + $dbw->dropTable( 'test' ); + } + + /** + * @param $dbw DatabaseBase + * @return void + */ + private function insertData( $dbw ) { + $range = range( 0, 1024 ); + $data = array(); + foreach( $range as $r ) { + $data[] = array( 'text' => $r ); + } + $dbw->insert( 'test', $data, __METHOD__ ); + } + + /** + * @param $dbw DatabaseBase + * @return void + */ + private function delete( $dbw ) { + $dbw->delete( 'text', '*', __METHOD__ ); + } + + /** + * @param $dbw DatabaseBase + * @return void + */ + private function truncate( $dbw ) { + $test = $dbw->tableName( 'test' ); + $dbw->query( "TRUNCATE TABLE $test" ); + } +} + +$maintClass = "BenchmarkDeleteTruncate"; +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/maintenance/benchmarks/bench_if_switch.php b/maintenance/benchmarks/bench_if_switch.php new file mode 100644 index 00000000..11c00b3c --- /dev/null +++ b/maintenance/benchmarks/bench_if_switch.php @@ -0,0 +1,88 @@ +mDescription = "Benchmark if elseif... versus switch case."; + } + + public function execute() { + $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 {} + } + + // 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; + default: + } + } +} + +$maintClass = 'bench_if_switch'; +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/maintenance/benchmarks/bench_strtr_str_replace.php b/maintenance/benchmarks/bench_strtr_str_replace.php new file mode 100644 index 00000000..ae576981 --- /dev/null +++ b/maintenance/benchmarks/bench_strtr_str_replace.php @@ -0,0 +1,50 @@ +mDescription = "Benchmark for strtr() vs str_replace()."; + } + + public function execute() { + $this->bench( array( + array( 'function' => array( $this, 'benchstrtr' ) ), + array( 'function' => array( $this, 'benchstr_replace' ) ), + array( 'function' => array( $this, 'benchstrtr_indirect' ) ), + array( 'function' => array( $this, 'benchstr_replace_indirect' ) ), + )); + print $this->getFormattedResults(); + } + + function benchstrtr() { + strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " ); + } + + function benchstr_replace() { + str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]"); + } + + + function benchstrtr_indirect() { + bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" ); + } + + function benchstr_replace_indirect() { + bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" ); + } + +} + +$maintClass = 'bench_strtr_str_replace'; +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/maintenance/benchmarks/bench_wfIsWindows.php b/maintenance/benchmarks/bench_wfIsWindows.php index 2f759e07..4c35221d 100644 --- a/maintenance/benchmarks/bench_wfIsWindows.php +++ b/maintenance/benchmarks/bench_wfIsWindows.php @@ -1,6 +1,24 @@ mDescription = "Benchmark for wfIsWindows."; } public function execute() { diff --git a/maintenance/benchmarks/benchmarkPurge.php b/maintenance/benchmarks/benchmarkPurge.php new file mode 100644 index 00000000..4ab7aa10 --- /dev/null +++ b/maintenance/benchmarks/benchmarkPurge.php @@ -0,0 +1,106 @@ +mDescription = "Benchmark the Squid purge functions."; + } + + public function execute() { + global $wgUseSquid, $wgSquidServers; + if ( !$wgUseSquid ) { + $this->error( "Squid purge benchmark doesn't do much without squid support on.", true ); + } else { + $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" ); + if ( $this->hasOption( 'count' ) ) { + $lengths = array( intval( $this->getOption( 'count' ) ) ); + } else { + $lengths = array( 1, 10, 100 ); + } + foreach ( $lengths as $length ) { + $urls = $this->randomUrlList( $length ); + $trial = $this->benchSquid( $urls ); + $this->output( $trial . "\n" ); + } + } + } + + /** + * 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? + */ + private function benchSquid( $urls, $trials = 1 ) { + $start = wfTime(); + for ( $i = 0; $i < $trials; $i++ ) { + SquidUpdate::purge( $urls ); + } + $delta = wfTime() - $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 + */ + private function randomUrlList( $length ) { + $list = array(); + for ( $i = 0; $i < $length; $i++ ) { + $list[] = $this->randomUrl(); + } + return $list; + } + + /** + * Return a random URL of the wiki. Not necessarily an actual title in the + * database, but at least a URL that looks like one. + */ + private function randomUrl() { + global $wgServer, $wgArticlePath; + return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath ); + } + + /** + * Create a random title string (not necessarily a Title object). + * For use with randomUrl(). + */ + private function randomTitle() { + $str = ''; + $length = mt_rand( 1, 20 ); + for ( $i = 0; $i < $length; $i++ ) { + $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) ); + } + return ucfirst( $str ); + } +} + +$maintClass = "BenchmarkPurge"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- cgit v1.2.3-54-g00ecf