MediaWiki  REL1_22
bench_delete_truncate.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/Benchmarker.php';
00025 
00031 class BenchmarkDeleteTruncate extends Benchmarker {
00032 
00033     public function __construct() {
00034         parent::__construct();
00035         $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
00036     }
00037 
00038     public function execute() {
00039         $dbw = wfGetDB( DB_MASTER );
00040 
00041         $test = $dbw->tableName( 'test' );
00042         $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
00043   test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
00044   text varbinary(255) NOT NULL
00045 );" );
00046 
00047         $this->insertData( $dbw );
00048 
00049         $start = microtime( true );
00050 
00051         $this->delete( $dbw );
00052 
00053         $end = microtime( true );
00054 
00055         echo "Delete: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 );
00056         echo "\r\n";
00057 
00058         $this->insertData( $dbw );
00059 
00060         $start = microtime( true );
00061 
00062         $this->truncate( $dbw );
00063 
00064         $end = microtime( true );
00065 
00066         echo "Truncate: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 );
00067         echo "\r\n";
00068 
00069         $dbw->dropTable( 'test' );
00070     }
00071 
00076     private function insertData( $dbw ) {
00077         $range = range( 0, 1024 );
00078         $data = array();
00079         foreach( $range as $r ) {
00080             $data[] = array( 'text' => $r );
00081         }
00082         $dbw->insert( 'test', $data, __METHOD__ );
00083     }
00084 
00089     private function delete( $dbw ) {
00090         $dbw->delete( 'text', '*', __METHOD__ );
00091     }
00092 
00097     private function truncate( $dbw ) {
00098         $test = $dbw->tableName( 'test' );
00099         $dbw->query( "TRUNCATE TABLE $test" );
00100     }
00101 }
00102 
00103 $maintClass = "BenchmarkDeleteTruncate";
00104 require_once RUN_MAINTENANCE_IF_MAIN;