35 parent::__construct();
43 $this->
error(
"CDN purge benchmark doesn't do much without CDN support on." );
47 $lengths = [ intval( $this->
getOption(
'count' ) ) ];
49 $lengths = [ 1, 10, 100 ];
51 foreach ( $lengths as $length ) {
52 $urls = $this->randomUrlList( $length );
53 $trial = $this->benchCdn( $urls );
54 $this->
output( $trial .
"\n" );
66 private function benchCdn( $urls, $trials = 1 ) {
67 $start = microtime(
true );
68 for ( $i = 0; $i < $trials; $i++ ) {
69 CdnCacheUpdate::purge( $urls );
71 $delta = microtime(
true ) - $start;
72 $pertrial = $delta / $trials;
73 $pertitle = $pertrial / count( $urls );
75 return sprintf(
"%4d titles in %6.2fms (%6.2fms each)",
76 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
84 private function randomUrlList( $length ) {
86 for ( $i = 0; $i < $length; $i++ ) {
87 $list[] = $this->randomUrl();
98 private function randomUrl() {
109 private function randomTitle() {
111 $length = mt_rand( 1, 20 );
112 for ( $i = 0; $i < $length; $i++ ) {
113 $str .= chr( mt_rand( ord(
'a' ), ord(
'z' ) ) );
116 return ucfirst( $str );
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
getOption( $name, $default=null)
Get an option, or return the default.