Kill "* @return void"
[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 */
49 private function insertData( $dbw ) {
50 $range = range( 0, 1024 );
51 $data = array();
52 foreach( $range as $r ) {
53 $data[] = array( 'text' => $r );
54 }
55 $dbw->insert( 'test', $data, __METHOD__ );
56 }
57
58 /**
59 * @param $dbw DatabaseBase
60 */
61 private function delete( $dbw ) {
62 $dbw->delete( 'text', '*', __METHOD__ );
63 }
64
65 /**
66 * @param $dbw DatabaseBase
67 */
68 private function truncate( $dbw ) {
69 $test = $dbw->tableName( 'test' );
70 $dbw->query( "TRUNCATE TABLE $test" );
71 }
72 }
73
74 $maintClass = "BenchmarkDeleteTruncate";
75 require_once( RUN_MAINTENANCE_IF_MAIN );