Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_delete_truncate.php
index 2a8d79a..794b743 100644 (file)
 
 require_once __DIR__ . '/Benchmarker.php';
 
+use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
 /**
  * Maintenance script that benchmarks SQL DELETE vs SQL TRUNCATE.
  *
  * @ingroup Benchmark
  */
 class BenchmarkDeleteTruncate extends Benchmarker {
+       protected $defaultCount = 10;
+
        public function __construct() {
                parent::__construct();
                $this->addDescription( 'Benchmarks SQL DELETE vs SQL TRUNCATE.' );
@@ -43,33 +48,30 @@ 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' );
        }
 
        /**
-        * @param Database $dbw
+        * @param IDatabase $dbw
         * @return void
         */
        private function insertData( $dbw ) {
@@ -82,7 +84,7 @@ class BenchmarkDeleteTruncate extends Benchmarker {
        }
 
        /**
-        * @param Database $dbw
+        * @param IDatabase $dbw
         * @return void
         */
        private function delete( $dbw ) {
@@ -90,7 +92,7 @@ class BenchmarkDeleteTruncate extends Benchmarker {
        }
 
        /**
-        * @param Database $dbw
+        * @param IMaintainableDatabase $dbw
         * @return void
         */
        private function truncate( $dbw ) {
@@ -99,5 +101,5 @@ class BenchmarkDeleteTruncate extends Benchmarker {
        }
 }
 
-$maintClass = "BenchmarkDeleteTruncate";
+$maintClass = BenchmarkDeleteTruncate::class;
 require_once RUN_MAINTENANCE_IF_MAIN;