37 parent::__construct();
38 $this->addDescription(
'Benchmark the CDN purge functions.' );
45 $this->error(
"CDN purge benchmark doesn't do much without CDN support on." );
47 $this->output(
"There are " . count(
$wgCdnServers ) .
" defined CDN servers:\n" );
48 if ( $this->hasOption(
'count' ) ) {
49 $lengths = [ intval( $this->getOption(
'count' ) ) ];
51 $lengths = [ 1, 10, 100 ];
53 foreach ( $lengths as $length ) {
54 $urls = $this->randomUrlList( $length );
55 $trial = $this->benchCdn( $urls );
56 $this->output( $trial .
"\n" );
68 private function benchCdn( $urls, $trials = 1 ) {
69 $start = microtime(
true );
70 for ( $i = 0; $i < $trials; $i++ ) {
71 CdnCacheUpdate::purge( $urls );
73 $delta = microtime(
true ) - $start;
74 $pertrial = $delta / $trials;
75 $pertitle = $pertrial / count( $urls );
77 return sprintf(
"%4d titles in %6.2fms (%6.2fms each)",
78 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
86 private function randomUrlList( $length ) {
88 for ( $i = 0; $i < $length; $i++ ) {
89 $list[] = $this->randomUrl();
100 private function randomUrl() {
111 private function randomTitle() {
113 $length = mt_rand( 1, 20 );
114 for ( $i = 0; $i < $length; $i++ ) {
115 $str .= chr( mt_rand( ord(
'a' ), ord(
'z' ) ) );
118 return ucfirst( $str );