r81261 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81260‎ | r81261 | r81262 >
Date:17:33, 31 January 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Add a fairly pants TRUNCATE vs DELETE benchmark...
Modified paths:
  • /trunk/phase3/maintenance/benchmarks/bench_delete_truncate.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/benchmarks/bench_delete_truncate.php
@@ -0,0 +1,78 @@
 2+<?php
 3+
 4+require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
 5+
 6+class BenchmarkPurge extends Benchmarker {
 7+
 8+ public function __construct() {
 9+ parent::__construct();
 10+ $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
 11+ }
 12+
 13+ public function execute() {
 14+ $dbw = wfGetDB( DB_MASTER );
 15+
 16+ $test = $dbw->tableName( 'test' );
 17+ $dbw->doQuery( "CREATE TABLE IF NOT EXISTS /*_*/$test (
 18+ test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 19+ text varbinary(255) NOT NULL
 20+);" );
 21+
 22+ $this->insertData( $dbw );
 23+
 24+ $start = wfTime();
 25+
 26+ $this->delete( $dbw );
 27+
 28+ $end = wfTime();
 29+
 30+ echo "Delete: " . $end - $start;
 31+ echo "\r\n";
 32+
 33+ $this->insertData( $dbw );
 34+
 35+ $start = wfTime();
 36+
 37+ $this->truncate( $dbw );
 38+
 39+ $end = wfTime();
 40+
 41+ echo "Truncate: " . $end - $start;
 42+ echo "\r\n";
 43+
 44+ $dbw->dropTable( 'test' );
 45+ }
 46+
 47+ /**
 48+ * @param $dbw DatabaseBase
 49+ * @return void
 50+ */
 51+ private function insertData( $dbw ) {
 52+ $range = range( 0, 1024 );
 53+ $data = array();
 54+ foreach( $range as $r ) {
 55+ $data[] = array( 'text' => $r );
 56+ }
 57+ $dbw->insert( 'test', $data, __METHOD__ );
 58+ }
 59+
 60+ /**
 61+ * @param $dbw DatabaseBase
 62+ * @return void
 63+ */
 64+ private function delete( $dbw ) {
 65+ $dbw->delete( 'text', '*', __METHOD__ );
 66+ }
 67+
 68+ /**
 69+ * @param $dbw DatabaseBase
 70+ * @return void
 71+ */
 72+ private function truncate( $dbw ) {
 73+ $test = $dbw->tableName( 'test' );
 74+ $dbw->doQuery( "TRUNCATE TABLE $test" );
 75+ }
 76+}
 77+
 78+$maintClass = "BenchmarkPurge";
 79+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/benchmarks/bench_delete_truncate.php
___________________________________________________________________
Added: svn:eol-style
180 + native

Comments

#Comment by 😂 (talk | contribs)   15:21, 18 April 2011

Fairly? I think you meant fancy :)

Status & tagging log