Pass OutputPage instance to MakeGlobalVariablesScript. Allows extensions to getTitle...
[mediawiki.git] / maintenance / benchmarks / bench_delete_truncate.php
blob9fe9bea991d923035a345048bbac2900b403090c
1 <?php
3 require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
5 class BenchmarkDeleteTruncate extends Benchmarker {
7 public function __construct() {
8 parent::__construct();
9 $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
12 public function execute() {
13 $dbw = wfGetDB( DB_MASTER );
15 $test = $dbw->tableName( 'test' );
16 $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
17 test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
18 text varbinary(255) NOT NULL
19 );" );
21 $this->insertData( $dbw );
23 $start = wfTime();
25 $this->delete( $dbw );
27 $end = wfTime();
29 echo "Delete: " . $end - $start;
30 echo "\r\n";
32 $this->insertData( $dbw );
34 $start = wfTime();
36 $this->truncate( $dbw );
38 $end = wfTime();
40 echo "Truncate: " . $end - $start;
41 echo "\r\n";
43 $dbw->dropTable( 'test' );
46 /**
47 * @param $dbw DatabaseBase
48 * @return void
50 private function insertData( $dbw ) {
51 $range = range( 0, 1024 );
52 $data = array();
53 foreach( $range as $r ) {
54 $data[] = array( 'text' => $r );
56 $dbw->insert( 'test', $data, __METHOD__ );
59 /**
60 * @param $dbw DatabaseBase
61 * @return void
63 private function delete( $dbw ) {
64 $dbw->delete( 'text', '*', __METHOD__ );
67 /**
68 * @param $dbw DatabaseBase
69 * @return void
71 private function truncate( $dbw ) {
72 $test = $dbw->tableName( 'test' );
73 $dbw->query( "TRUNCATE TABLE $test" );
77 $maintClass = "BenchmarkDeleteTruncate";
78 require_once( RUN_MAINTENANCE_IF_MAIN );