33 parent::__construct();
41 $this->
error(
"CDN purge benchmark doesn't do much without CDN support on." );
45 $lengths = [ intval( $this->
getOption(
'count' ) ) ];
47 $lengths = [ 1, 10, 100 ];
49 foreach ( $lengths as $length ) {
50 $urls = $this->randomUrlList( $length );
51 $trial = $this->benchCdn( $urls );
52 $this->
output( $trial .
"\n" );
64 private function benchCdn( $urls, $trials = 1 ) {
65 $start = microtime(
true );
66 for ( $i = 0; $i < $trials; $i++ ) {
69 $delta = microtime(
true ) - $start;
70 $pertrial = $delta / $trials;
71 $pertitle = $pertrial / count( $urls );
73 return sprintf(
"%4d titles in %6.2fms (%6.2fms each)",
74 count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
82 private function randomUrlList( $length ) {
84 for ( $i = 0; $i < $length; $i++ ) {
85 $list[] = $this->randomUrl();
96 private function randomUrl() {
107 private function randomTitle() {
109 $length = mt_rand( 1, 20 );
110 for ( $i = 0; $i < $length; $i++ ) {
111 $str .= chr( mt_rand( ord(
'a' ), ord(
'z' ) ) );
114 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.