Merge "Add CLDRPluralRuleError, added in parent commit, to the AutoLoader"
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_delete_truncate.php
1 <?php
2 /**
3 * @file
4 * @ingroup Benchmark
5 */
6
7 require_once( __DIR__ . '/Benchmarker.php' );
8
9 class BenchmarkDeleteTruncate extends Benchmarker {
10
11 public function __construct() {
12 parent::__construct();
13 $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
14 }
15
16 public function execute() {
17 $dbw = wfGetDB( DB_MASTER );
18
19 $test = $dbw->tableName( 'test' );
20 $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
21 test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
22 text varbinary(255) NOT NULL
23 );" );
24
25 $this->insertData( $dbw );
26
27 $start = wfTime();
28
29 $this->delete( $dbw );
30
31 $end = wfTime();
32
33 echo "Delete: " . $end - $start;
34 echo "\r\n";
35
36 $this->insertData( $dbw );
37
38 $start = wfTime();
39
40 $this->truncate( $dbw );
41
42 $end = wfTime();
43
44 echo "Truncate: " . $end - $start;
45 echo "\r\n";
46
47 $dbw->dropTable( 'test' );
48 }
49
50 /**
51 * @param $dbw DatabaseBase
52 * @return void
53 */
54 private function insertData( $dbw ) {
55 $range = range( 0, 1024 );
56 $data = array();
57 foreach( $range as $r ) {
58 $data[] = array( 'text' => $r );
59 }
60 $dbw->insert( 'test', $data, __METHOD__ );
61 }
62
63 /**
64 * @param $dbw DatabaseBase
65 * @return void
66 */
67 private function delete( $dbw ) {
68 $dbw->delete( 'text', '*', __METHOD__ );
69 }
70
71 /**
72 * @param $dbw DatabaseBase
73 * @return void
74 */
75 private function truncate( $dbw ) {
76 $test = $dbw->tableName( 'test' );
77 $dbw->query( "TRUNCATE TABLE $test" );
78 }
79 }
80
81 $maintClass = "BenchmarkDeleteTruncate";
82 require_once( RUN_MAINTENANCE_IF_MAIN );