From 3ff34c1df360627c7c05737994b47335789d3a28 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Mon, 31 Jan 2011 17:33:30 +0000 Subject: [PATCH] Add a fairly pants TRUNCATE vs DELETE benchmark... --- .../benchmarks/bench_delete_truncate.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 maintenance/benchmarks/bench_delete_truncate.php diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php new file mode 100644 index 0000000000..3a09e1462a --- /dev/null +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -0,0 +1,78 @@ +mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE."; + } + + public function execute() { + $dbw = wfGetDB( DB_MASTER ); + + $test = $dbw->tableName( 'test' ); + $dbw->doQuery( "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 = wfTime(); + + $this->delete( $dbw ); + + $end = wfTime(); + + echo "Delete: " . $end - $start; + echo "\r\n"; + + $this->insertData( $dbw ); + + $start = wfTime(); + + $this->truncate( $dbw ); + + $end = wfTime(); + + echo "Truncate: " . $end - $start; + echo "\r\n"; + + $dbw->dropTable( 'test' ); + } + + /** + * @param $dbw DatabaseBase + * @return void + */ + private function insertData( $dbw ) { + $range = range( 0, 1024 ); + $data = array(); + foreach( $range as $r ) { + $data[] = array( 'text' => $r ); + } + $dbw->insert( 'test', $data, __METHOD__ ); + } + + /** + * @param $dbw DatabaseBase + * @return void + */ + private function delete( $dbw ) { + $dbw->delete( 'text', '*', __METHOD__ ); + } + + /** + * @param $dbw DatabaseBase + * @return void + */ + private function truncate( $dbw ) { + $test = $dbw->tableName( 'test' ); + $dbw->doQuery( "TRUNCATE TABLE $test" ); + } +} + +$maintClass = "BenchmarkPurge"; +require_once( RUN_MAINTENANCE_IF_MAIN ); \ No newline at end of file -- 2.20.1