r99939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99938‎ | r99939 | r99940 >
Date:03:32, 16 October 2011
Author:reedy
Status:ok
Tags:
Comment:
svn:eol-style native
Modified paths:
  • /trunk/phase3/maintenance/benchmarks/benchmarkHooks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/benchmarks/benchmarkHooks.php
@@ -1,80 +1,80 @@
2 -<?php
3 -/**
4 - * This program is free software; you can redistribute it and/or modify
5 - * it under the terms of the GNU General Public License as published by
6 - * the Free Software Foundation; either version 2 of the License, or
7 - * (at your option) any later version.
8 - *
9 - * This program is distributed in the hope that it will be useful,
10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 - * GNU General Public License for more details.
13 - *
14 - * You should have received a copy of the GNU General Public License along
15 - * with this program; if not, write to the Free Software Foundation, Inc.,
16 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 - * http://www.gnu.org/copyleft/gpl.html
18 - *
19 - * @file
20 - * @ingroup Maintenance
21 - */
22 -
23 -require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
24 -
25 -class BenchmarkHooks extends Benchmarker {
26 -
27 - public function __construct() {
28 - parent::__construct();
29 - $this->mDescription = "Benchmark MediaWiki Hooks.";
30 - }
31 -
32 - public function execute() {
33 - global $wgHooks;
34 - $wgHooks['Test'] = array();
35 -
36 - $time = $this->benchHooks();
37 - $this->output( 'Empty hook: ' . $time . "\n" );
38 -
39 - $wgHooks['Test'][] = array( $this, 'test' );
40 - $time = $this->benchHooks();
41 - $this->output( 'Loaded (one) hook: ' . $time . "\n" );
42 -
43 - for( $i = 0; $i < 9; $i++ ) {
44 - $wgHooks['Test'][] = array( $this, 'test' );
45 - }
46 - $time = $this->benchHooks();
47 - $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
48 -
49 - for( $i = 0; $i < 90; $i++ ) {
50 - $wgHooks['Test'][] = array( $this, 'test' );
51 - }
52 - $time = $this->benchHooks();
53 - $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
54 - $this->output( "\n" );
55 - }
56 -
57 - /**
58 - * @param $trials int
59 - * @return string
60 - */
61 - private function benchHooks( $trials = 10 ) {
62 - $start = wfTime();
63 - for ( $i = 0; $i < $trials; $i++ ) {
64 - wfRunHooks( 'Test' );
65 - }
66 - $delta = wfTime() - $start;
67 - $pertrial = $delta / $trials;
68 - return sprintf( "Took %6.2fs",
69 - $pertrial );
70 - }
71 -
72 - /**
73 - * @return bool
74 - */
75 - public function test() {
76 - return true;
77 - }
78 -}
79 -
80 -$maintClass = "BenchmarkHooks";
81 -require_once( RUN_MAINTENANCE_IF_MAIN );
 2+<?php
 3+/**
 4+ * This program is free software; you can redistribute it and/or modify
 5+ * it under the terms of the GNU General Public License as published by
 6+ * the Free Software Foundation; either version 2 of the License, or
 7+ * (at your option) any later version.
 8+ *
 9+ * This program is distributed in the hope that it will be useful,
 10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 12+ * GNU General Public License for more details.
 13+ *
 14+ * You should have received a copy of the GNU General Public License along
 15+ * with this program; if not, write to the Free Software Foundation, Inc.,
 16+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 17+ * http://www.gnu.org/copyleft/gpl.html
 18+ *
 19+ * @file
 20+ * @ingroup Maintenance
 21+ */
 22+
 23+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
 24+
 25+class BenchmarkHooks extends Benchmarker {
 26+
 27+ public function __construct() {
 28+ parent::__construct();
 29+ $this->mDescription = "Benchmark MediaWiki Hooks.";
 30+ }
 31+
 32+ public function execute() {
 33+ global $wgHooks;
 34+ $wgHooks['Test'] = array();
 35+
 36+ $time = $this->benchHooks();
 37+ $this->output( 'Empty hook: ' . $time . "\n" );
 38+
 39+ $wgHooks['Test'][] = array( $this, 'test' );
 40+ $time = $this->benchHooks();
 41+ $this->output( 'Loaded (one) hook: ' . $time . "\n" );
 42+
 43+ for( $i = 0; $i < 9; $i++ ) {
 44+ $wgHooks['Test'][] = array( $this, 'test' );
 45+ }
 46+ $time = $this->benchHooks();
 47+ $this->output( 'Loaded (ten) hook: ' . $time . "\n" );
 48+
 49+ for( $i = 0; $i < 90; $i++ ) {
 50+ $wgHooks['Test'][] = array( $this, 'test' );
 51+ }
 52+ $time = $this->benchHooks();
 53+ $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" );
 54+ $this->output( "\n" );
 55+ }
 56+
 57+ /**
 58+ * @param $trials int
 59+ * @return string
 60+ */
 61+ private function benchHooks( $trials = 10 ) {
 62+ $start = wfTime();
 63+ for ( $i = 0; $i < $trials; $i++ ) {
 64+ wfRunHooks( 'Test' );
 65+ }
 66+ $delta = wfTime() - $start;
 67+ $pertrial = $delta / $trials;
 68+ return sprintf( "Took %6.2fs",
 69+ $pertrial );
 70+ }
 71+
 72+ /**
 73+ * @return bool
 74+ */
 75+ public function test() {
 76+ return true;
 77+ }
 78+}
 79+
 80+$maintClass = "BenchmarkHooks";
 81+require_once( RUN_MAINTENANCE_IF_MAIN );
Property changes on: trunk/phase3/maintenance/benchmarks/benchmarkHooks.php
___________________________________________________________________
Added: svn:eol-style
8282 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99919Rudimentary hook benchmarksreedy22:15, 15 October 2011

Status & tagging log