MediaWiki  REL1_19
bench_delete_truncate.php
Go to the documentation of this file.
00001 <?php
00007 require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
00008 
00009 class BenchmarkDeleteTruncate extends Benchmarker {
00010 
00011         public function __construct() {
00012                 parent::__construct();
00013                 $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
00014         }
00015 
00016         public function execute() {
00017                 $dbw = wfGetDB( DB_MASTER );
00018 
00019                 $test = $dbw->tableName( 'test' );
00020                 $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
00021   test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
00022   text varbinary(255) NOT NULL
00023 );" );
00024 
00025                 $this->insertData( $dbw );
00026 
00027                 $start = wfTime();
00028 
00029                 $this->delete( $dbw );
00030 
00031                 $end = wfTime();
00032 
00033                 echo "Delete: " . $end - $start;
00034                 echo "\r\n";
00035 
00036                 $this->insertData( $dbw );
00037 
00038                 $start = wfTime();
00039 
00040                 $this->truncate( $dbw );
00041 
00042                 $end = wfTime();
00043 
00044                 echo "Truncate: " . $end - $start;
00045                 echo "\r\n";
00046 
00047                 $dbw->dropTable( 'test' );
00048         }
00049 
00054         private function insertData( $dbw ) {
00055                 $range = range( 0, 1024 );
00056                 $data = array();
00057                 foreach( $range as $r ) {
00058                         $data[] = array( 'text' => $r );
00059                 }
00060                 $dbw->insert( 'test', $data, __METHOD__ );
00061         }
00062 
00067         private function delete( $dbw ) {
00068                 $dbw->delete( 'text', '*', __METHOD__ );
00069         }
00070 
00075         private function truncate( $dbw ) {
00076                 $test = $dbw->tableName( 'test' );
00077                 $dbw->query( "TRUNCATE TABLE $test" );
00078         }
00079 }
00080 
00081 $maintClass = "BenchmarkDeleteTruncate";
00082 require_once( RUN_MAINTENANCE_IF_MAIN );