00001 <?php 00010 require_once( "commandLine.inc" ); 00011 00018 function benchSquid( $urls, $trials = 1 ) { 00019 $start = wfTime(); 00020 for( $i = 0; $i < $trials; $i++) { 00021 SquidUpdate::purge( $urls ); 00022 } 00023 $delta = wfTime() - $start; 00024 $pertrial = $delta / $trials; 00025 $pertitle = $pertrial / count( $urls ); 00026 return sprintf( "%4d titles in %6.2fms (%6.2fms each)", 00027 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 ); 00028 } 00029 00034 function randomUrlList( $length ) { 00035 $list = array(); 00036 for( $i = 0; $i < $length; $i++ ) { 00037 $list[] = randomUrl(); 00038 } 00039 return $list; 00040 } 00041 00046 function randomUrl() { 00047 global $wgServer, $wgArticlePath; 00048 return $wgServer . str_replace( '$1', randomTitle(), $wgArticlePath ); 00049 } 00050 00055 function randomTitle() { 00056 $str = ''; 00057 $length = mt_rand( 1, 20 ); 00058 for( $i = 0; $i < $length; $i++ ) { 00059 $str .= chr( mt_rand( ord('a'), ord('z') ) ); 00060 } 00061 return ucfirst( $str ); 00062 } 00063 00064 if( !$wgUseSquid ) { 00065 wfDie( "Squid purge benchmark doesn't do much without squid support on.\n" ); 00066 } else { 00067 printf( "There are %d defined squid servers:\n", count( $wgSquidServers ) ); 00068 #echo implode( "\n", $wgSquidServers ) . "\n"; 00069 if( isset( $options['count'] ) ) { 00070 $lengths = array( intval( $options['count'] ) ); 00071 } else { 00072 $lengths = array( 1, 10, 100 ); 00073 } 00074 foreach( $lengths as $length ) { 00075 $urls = randomUrlList( $length ); 00076 $trial = benchSquid( $urls ); 00077 print "$trial\n"; 00078 } 00079 }