26 parent::__construct();
27 $this->
addOption(
'file',
'Path to file containing the input text',
false,
true );
31 $file = $this->
getOption(
'file', __DIR__ .
'/data/tidy/australia-untidy.html.gz' );
33 if ( $html ===
false ) {
34 $this->
fatalError(
"Unable to open input file" );
37 $this->benchmark( $html );
40 private function benchmark( $html ) {
42 $contLang = $services->getContentLanguage();
43 $tidy = $services->getTidy();
47 for ( $j = 1; $j <= $outerCount; $j++ ) {
48 $t = microtime(
true );
49 for ( $i = 0; $i < $innerCount; $i++ ) {
51 print $contLang->formatSize( memory_get_usage(
true ) ) .
"\n";
53 $t = ( ( microtime(
true ) -
$t ) / $innerCount ) * 1000;
59 sort( $times, SORT_NUMERIC );
65 $median = $times[ ( $n - 1 ) / 2 ];
67 $median = ( $times[$n / 2] + $times[$n / 2 - 1] ) / 2;
69 $mean = array_sum( $times ) / $n;
71 print
"Minimum: $min ms\n";
72 print
"Median: $median ms\n";
73 print
"Mean: $mean ms\n";
74 print
"Maximum: $max ms\n";
75 print
"Memory usage: " . $contLang->formatSize( memory_get_usage(
true ) ) .
"\n";
76 print
"Peak memory usage: " .
77 $contLang->formatSize( memory_get_peak_usage(
true ) ) .
"\n";
getServiceContainer()
Returns the main service container.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.