addDescription( 'Benchmarks SQL DELETE vs SQL TRUNCATE.' ); } public function execute() { $dbw = $this->getDB( DB_MASTER ); $test = $dbw->tableName( 'test' ); $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test ( test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, 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"; $dbw->dropTable( 'test' ); } /** * @param IDatabase $dbw * @return void */ private function insertData( $dbw ) { $range = range( 0, 1024 ); $data = []; foreach ( $range as $r ) { $data[] = [ 'text' => $r ]; } $dbw->insert( 'test', $data, __METHOD__ ); } /** * @param IDatabase $dbw * @return void */ private function delete( $dbw ) { $dbw->delete( 'text', '*', __METHOD__ ); } /** * @param IMaintainableDatabase $dbw * @return void */ private function truncate( $dbw ) { $test = $dbw->tableName( 'test' ); $dbw->query( "TRUNCATE TABLE $test" ); } } $maintClass = "BenchmarkDeleteTruncate"; require_once RUN_MAINTENANCE_IF_MAIN;