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