summaryrefslogtreecommitdiff
path: root/maintenance/benchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'maintenance/benchmarks')
-rw-r--r--maintenance/benchmarks/Benchmarker.php23
-rw-r--r--maintenance/benchmarks/bench_HTTP_HTTPS.php21
-rw-r--r--maintenance/benchmarks/bench_delete_truncate.php78
-rw-r--r--maintenance/benchmarks/bench_if_switch.php88
-rw-r--r--maintenance/benchmarks/bench_strtr_str_replace.php50
-rw-r--r--maintenance/benchmarks/bench_wfIsWindows.php21
-rw-r--r--maintenance/benchmarks/benchmarkPurge.php106
7 files changed, 381 insertions, 6 deletions
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 @@
<?php
/**
- * Create a doxygen subgroup of Maintenance for benchmarks
* @defgroup Benchmark Benchmark
- * @ingroup Maintenance
*/
/**
- * TODO: report PHP version, OS ..
+ * Create a doxygen subgroup of Maintenance for benchmarks
+ *
+ * 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
+ *
+ * @todo Report PHP version, OS ..
* @file
- * @ingroup Benchmark
+ * @ingroup Maintenance Benchmark
*/
require_once( dirname( __FILE__ ) . '/../Maintenance.php' );
diff --git a/maintenance/benchmarks/bench_HTTP_HTTPS.php b/maintenance/benchmarks/bench_HTTP_HTTPS.php
index 13d15fce..0038b2d1 100644
--- a/maintenance/benchmarks/bench_HTTP_HTTPS.php
+++ b/maintenance/benchmarks/bench_HTTP_HTTPS.php
@@ -1,6 +1,24 @@
<?php
/**
* This come from r75429 message
+ *
+ * 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 Maintenance
* @author Platonides
*/
@@ -8,7 +26,8 @@ require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
class bench_HTTP_HTTPS extends Benchmarker {
public function __construct() {
- parent::__construct();
+ parent::__construct();
+ $this->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 @@
+<?php
+
+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
+
+class BenchmarkDeleteTruncate extends Benchmarker {
+
+ public function __construct() {
+ parent::__construct();
+ $this->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 @@
+<?php
+/**
+ * This come from r75429 message
+ *
+ * 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 Maintenance
+ * @author Platonides
+ */
+
+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
+class bench_if_switch extends Benchmarker {
+
+ public function __construct() {
+ parent::__construct();
+ $this->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 @@
+<?php
+
+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
+
+function bfNormalizeTitleStrTr( $str ) {
+ return strtr( $str, '_', ' ' );
+}
+
+function bfNormalizeTitleStrReplace( $str ) {
+ return str_replace( '_', ' ', $str );
+}
+
+class bench_strtr_str_replace extends Benchmarker {
+
+ public function __construct() {
+ parent::__construct();
+ $this->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 @@
<?php
/**
* This come from r75429 message
+ *
+ * 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 Maintenance
* @author Platonides
*/
@@ -8,7 +26,8 @@ require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
class bench_wfIsWindows extends Benchmarker {
public function __construct() {
- parent::__construct();
+ parent::__construct();
+ $this->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 @@
+<?php
+/**
+ * Squid purge benchmark script
+ *
+ * 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 Maintenance
+ */
+
+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
+
+class BenchmarkPurge extends Benchmarker {
+
+ public function __construct() {
+ parent::__construct();
+ $this->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 );