no need for position:absolute
[lhc/web/wiklou.git] / maintenance / benchmarkPurge.php
1 <?php
2 /**
3 * Squid purge benchmark script
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
7
8 /** */
9 require_once( "commandLine.inc" );
10
11 /** @todo document */
12 function benchSquid( $urls, $trials = 1 ) {
13 $start = wfTime();
14 for( $i = 0; $i < $trials; $i++) {
15 SquidUpdate::purge( $urls );
16 }
17 $delta = wfTime() - $start;
18 $pertrial = $delta / $trials;
19 $pertitle = $pertrial / count( $urls );
20 return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
21 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
22 }
23
24 /** @todo document */
25 function randomUrlList( $length ) {
26 $list = array();
27 for( $i = 0; $i < $length; $i++ ) {
28 $list[] = randomUrl();
29 }
30 return $list;
31 }
32
33 /** @todo document */
34 function randomUrl() {
35 global $wgServer, $wgArticlePath;
36 return $wgServer . str_replace( '$1', randomTitle(), $wgArticlePath );
37 }
38
39 /** @todo document */
40 function randomTitle() {
41 $str = '';
42 $length = mt_rand( 1, 20 );
43 for( $i = 0; $i < $length; $i++ ) {
44 $str .= chr( mt_rand( ord('a'), ord('z') ) );
45 }
46 return ucfirst( $str );
47 }
48
49 if( !$wgUseSquid ) {
50 die( "Squid purge benchmark doesn't do much without squid support on.\n" );
51 } else {
52 printf( "There are %d defined squid servers:\n", count( $wgSquidServers ) );
53 #echo implode( "\n", $wgSquidServers ) . "\n";
54 if( isset( $options['count'] ) ) {
55 $lengths = array( IntVal( $options['count'] ) );
56 } else {
57 $lengths = array( 1, 10, 100 );
58 }
59 foreach( $lengths as $length ) {
60 $urls = randomUrlList( $length );
61 $trial = benchSquid( $urls );
62 print "$trial\n";
63 }
64 }
65 ?>