Group related functions
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_delete_truncate.php
1 <?php
2
3 require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
4
5 class BenchmarkDeleteTruncate extends Benchmarker {
6
7 public function __construct() {
8 parent::__construct();
9 $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
10 }
11
12 public function execute() {
13 $dbw = wfGetDB( DB_MASTER );
14
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 );" );
20
21 $this->insertData( $dbw );
22
23 $start = wfTime();
24
25 $this->delete( $dbw );
26
27 $end = wfTime();
28
29 echo "Delete: " . $end - $start;
30 echo "\r\n";
31
32 $this->insertData( $dbw );
33
34 $start = wfTime();
35
36 $this->truncate( $dbw );
37
38 $end = wfTime();
39
40 echo "Truncate: " . $end - $start;
41 echo "\r\n";
42
43 $dbw->dropTable( 'test' );
44 }
45
46 /**
47 * @param $dbw DatabaseBase
48 * @return void
49 */
50 private function insertData( $dbw ) {
51 $range = range( 0, 1024 );
52 $data = array();
53 foreach( $range as $r ) {
54 $data[] = array( 'text' => $r );
55 }
56 $dbw->insert( 'test', $data, __METHOD__ );
57 }
58
59 /**
60 * @param $dbw DatabaseBase
61 * @return void
62 */
63 private function delete( $dbw ) {
64 $dbw->delete( 'text', '*', __METHOD__ );
65 }
66
67 /**
68 * @param $dbw DatabaseBase
69 * @return void
70 */
71 private function truncate( $dbw ) {
72 $test = $dbw->tableName( 'test' );
73 $dbw->query( "TRUNCATE TABLE $test" );
74 }
75 }
76
77 $maintClass = "BenchmarkDeleteTruncate";
78 require_once( RUN_MAINTENANCE_IF_MAIN );