Merge "Align mediawiki.ui vars with CSS color guidelines"
[lhc/web/wiklou.git] / maintenance / benchmarks / benchmarkParse.php
index b81f9fd..ce38dad 100644 (file)
@@ -41,7 +41,10 @@ class BenchmarkParse extends Maintenance {
                parent::__construct();
                $this->addDescription( 'Benchmark parse operation' );
                $this->addArg( 'title', 'The name of the page to parse' );
-               $this->addOption( 'cold', 'Don\'t repeat the parse operation to warm the cache' );
+               $this->addOption( 'warmup', 'Repeat the parse operation this number of times to warm the cache',
+                       false, true );
+               $this->addOption( 'loops', 'Number of times to repeat parse operation post-warmup',
+                       false, true );
                $this->addOption( 'page-time',
                        'Use the version of the page which was current at the given time',
                        false, true );
@@ -81,22 +84,30 @@ class BenchmarkParse extends Maintenance {
                        exit( 1 );
                }
 
-               if ( !$this->hasOption( 'cold' ) ) {
+               $warmup = $this->getOption( 'warmup', 1 );
+               for ( $i = 0; $i < $warmup; $i++ ) {
                        $this->runParser( $revision );
                }
 
+               $loops = $this->getOption( 'loops', 1 );
+               if ( $loops < 1 ) {
+                       $this->error( 'Invalid number of loops specified', true );
+               }
                $startUsage = getrusage();
                $startTime = microtime( true );
-               $this->runParser( $revision );
+               for ( $i = 0; $i < $loops; $i++ ) {
+                       $this->runParser( $revision );
+               }
                $endUsage = getrusage();
                $endTime = microtime( true );
 
                printf( "CPU time = %.3f s, wall clock time = %.3f s\n",
                        // CPU time
-                       $endUsage['ru_utime.tv_sec'] + $endUsage['ru_utime.tv_usec'] * 1e-6
-                       - $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1e-6,
+                       $endUsage['ru_utime.tv_sec'] + $endUsage['ru_utime.tv_usec'] * 1e-6
+                       - $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1e-6 ) / $loops,
                        // Wall clock time
-                       $endTime - $startTime );
+                       ( $endTime - $startTime ) / $loops
+               );
        }
 
        /**