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.' );
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 ) {
}
/**
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return void
*/
private function delete( $dbw ) {
}
/**
- * @param Database $dbw
+ * @param IMaintainableDatabase $dbw
* @return void
*/
private function truncate( $dbw ) {
}
}
-$maintClass = "BenchmarkDeleteTruncate";
+$maintClass = BenchmarkDeleteTruncate::class;
require_once RUN_MAINTENANCE_IF_MAIN;