28 parent::__construct();
29 $this->addOption(
'file',
'Path to file containing the input text',
false,
true );
33 $file = $this->getOption(
'file', __DIR__ .
'/data/tidy/australia-untidy.html.gz' );
34 $html = $this->loadFile( $file );
35 if ( $html ===
false ) {
36 $this->fatalError(
"Unable to open input file" );
39 $this->benchmark( $html );
42 private function benchmark( $html ) {
43 $services = $this->getServiceContainer();
44 $contLang = $services->getContentLanguage();
45 $tidy = $services->getTidy();
49 for ( $j = 1; $j <= $outerCount; $j++ ) {
50 $t = microtime(
true );
51 for ( $i = 0; $i < $innerCount; $i++ ) {
53 print $contLang->formatSize( memory_get_usage(
true ) ) .
"\n";
55 $t = ( ( microtime(
true ) -
$t ) / $innerCount ) * 1000;
61 sort( $times, SORT_NUMERIC );
67 $median = $times[ ( $n - 1 ) / 2 ];
69 $median = ( $times[$n / 2] + $times[$n / 2 - 1] ) / 2;
71 $mean = array_sum( $times ) / $n;
73 print
"Minimum: $min ms\n";
74 print
"Median: $median ms\n";
75 print
"Mean: $mean ms\n";
76 print
"Maximum: $max ms\n";
77 print
"Memory usage: " . $contLang->formatSize( memory_get_usage(
true ) ) .
"\n";
78 print
"Peak memory usage: " .
79 $contLang->formatSize( memory_get_peak_usage(
true ) ) .
"\n";