Merge "mw.Feedback: If the message is posted remotely, link the title correctly"
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_delete_truncate.php
index 2369d99..794b743 100644 (file)
@@ -32,6 +32,8 @@ use Wikimedia\Rdbms\IMaintainableDatabase;
  * @ingroup Benchmark
  */
 class BenchmarkDeleteTruncate extends Benchmarker {
+       protected $defaultCount = 10;
+
        public function __construct() {
                parent::__construct();
                $this->addDescription( 'Benchmarks SQL DELETE vs SQL TRUNCATE.' );
@@ -46,27 +48,24 @@ class BenchmarkDeleteTruncate extends Benchmarker {
   text varbinary(255) NOT NULL
 );" );
 
-               $this->insertData( $dbw );
-
-               $start = microtime( true );
-
-               $this->delete( $dbw );
-
-               $end = microtime( true );
-
-               echo "Delete: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 );
-               echo "\r\n";
-
-               $this->insertData( $dbw );
-
-               $start = microtime( true );
-
-               $this->truncate( $dbw );
-
-               $end = microtime( true );
-
-               echo "Truncate: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 );
-               echo "\r\n";
+               $this->bench( [
+                       'Delete' => [
+                               'setup' => function () use ( $dbw ) {
+                                       $this->insertData( $dbw );
+                               },
+                               'function' => function () use ( $dbw ) {
+                                       $this->delete( $dbw );
+                               }
+                       ],
+                       'Truncate' => [
+                               'setup' => function () use ( $dbw ) {
+                                       $this->insertData( $dbw );
+                               },
+                               'function' => function () use ( $dbw ) {
+                                       $this->truncate( $dbw );
+                               }
+                       ]
+               ] );
 
                $dbw->dropTable( 'test' );
        }
@@ -102,5 +101,5 @@ class BenchmarkDeleteTruncate extends Benchmarker {
        }
 }
 
-$maintClass = "BenchmarkDeleteTruncate";
+$maintClass = BenchmarkDeleteTruncate::class;
 require_once RUN_MAINTENANCE_IF_MAIN;