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