Rudimentary hook benchmarks
authorSam Reed <reedy@users.mediawiki.org>
Sat, 15 Oct 2011 22:15:36 +0000 (22:15 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 15 Oct 2011 22:15:36 +0000 (22:15 +0000)
maintenance/benchmarks/benchmarkHooks.php [new file with mode: 0644]

diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php
new file mode 100644 (file)
index 0000000..a9b4722
--- /dev/null
@@ -0,0 +1,73 @@
+<?php\r
+/**\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License along\r
+ * with this program; if not, write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ * http://www.gnu.org/copyleft/gpl.html\r
+ *\r
+ * @file\r
+ * @ingroup Maintenance\r
+ */\r
+\r
+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );\r
+\r
+class BenchmarkHooks extends Benchmarker {\r
+\r
+       public function __construct() {\r
+               parent::__construct();\r
+               $this->mDescription = "Benchmark MediaWiki Hooks.";\r
+       }\r
+\r
+       public function execute() {\r
+               $time = $this->benchEmptyHooks();\r
+               $this->output( 'Empty hook: ' . $time . "\n" );\r
+               $time = $this->benchLoadedHooks();\r
+               $this->output( 'Loaded hook: ' . $time . "\n" );\r
+               $this->output( "\n" );\r
+       }\r
+\r
+       private function benchEmptyHooks( $trials = 1 ) {\r
+               global $wgHooks;\r
+               $wgHooks['Test'] = array();\r
+\r
+               $start = wfTime();\r
+               for ( $i = 0; $i < $trials; $i++ ) {\r
+                       wfRunHooks( 'Test' );\r
+               }\r
+               $delta = wfTime() - $start;\r
+               $pertrial = $delta / $trials;\r
+               return sprintf( "Took %6.2fms",\r
+                       $pertrial );\r
+       }\r
+\r
+       private function benchLoadedHooks( $trials = 1 ) {\r
+               global $wgHooks;\r
+               $wgHooks['Test'][] = array( $this, 'test' );\r
+\r
+               $start = wfTime();\r
+               for ( $i = 0; $i < $trials; $i++ ) {\r
+                       wfRunHooks( 'Test' );\r
+               }\r
+               $delta = wfTime() - $start;\r
+               $pertrial = $delta / $trials;\r
+               return sprintf( "Took %6.2fms",\r
+                       $pertrial );\r
+       }\r
+\r
+       public function test() {\r
+               return true;\r
+       }\r
+}\r
+\r
+$maintClass = "BenchmarkHooks";\r
+require_once( RUN_MAINTENANCE_IF_MAIN );\r