3 require_once( dirname( __FILE__
) . '/Benchmarker.php' );
5 class BenchmarkDeleteTruncate
extends Benchmarker
{
7 public function __construct() {
9 $this->mDescription
= "Benchmarks SQL DELETE vs SQL TRUNCATE.";
12 public function execute() {
13 $dbw = wfGetDB( DB_MASTER
);
15 $test = $dbw->tableName( 'test' );
16 $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
17 test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
18 text varbinary(255) NOT NULL
21 $this->insertData( $dbw );
25 $this->delete( $dbw );
29 echo "Delete: " . $end - $start;
32 $this->insertData( $dbw );
36 $this->truncate( $dbw );
40 echo "Truncate: " . $end - $start;
43 $dbw->dropTable( 'test' );
47 * @param $dbw DatabaseBase
49 private function insertData( $dbw ) {
50 $range = range( 0, 1024 );
52 foreach( $range as $r ) {
53 $data[] = array( 'text' => $r );
55 $dbw->insert( 'test', $data, __METHOD__
);
59 * @param $dbw DatabaseBase
61 private function delete( $dbw ) {
62 $dbw->delete( 'text', '*', __METHOD__
);
66 * @param $dbw DatabaseBase
68 private function truncate( $dbw ) {
69 $test = $dbw->tableName( 'test' );
70 $dbw->query( "TRUNCATE TABLE $test" );
74 $maintClass = "BenchmarkDeleteTruncate";
75 require_once( RUN_MAINTENANCE_IF_MAIN
);