-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmysql.php
64 lines (49 loc) · 1.68 KB
/
mysql.php
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
<?php
require 'Benchmark/Timer.php';
$timer = new Benchmark_Timer();
$mysql = new mysqli("localhost", "testuser", "testpass", "test");
$points = array(1000, 10000, 100000, 500000, 1000000);
foreach($points as $val){
flush_mysql();
$startmark = $val . ' start';
$stopmark = $val . ' stop';
$timer->setMarker($startmark);
cycle($val);
$timer->setMarker($stopmark);
print $val . ': ' . $timer->timeElapsed($startmark, $stopmark) . "\n";
}
$mysql->close();
function flush_mysql(){
global $mysql;
$mysql->query("DROP TABLE IF EXISTS `php_insert_bm`");
$mysql->query("DROP TABLE IF EXISTS `php_insert_bm_coords`");
$mysql->query("CREATE TABLE `php_insert_bm_coords`(
`id` int unsigned not null auto_increment,
`x` int not null,
`y` int not null,
PRIMARY KEY (`id`)
)");
$mysql->query("CREATE TABLE `php_insert_bm`(
`id` int unsigned not null auto_increment,
`text` varchar(255) not null,
`count` int not null,
`coords_id` int unsigned not null,
PRIMARY KEY (`id`)
)");
# empty init entries
$mysql->query("INSERT php_insert_bm_coords(x,y) VALUES(0, 0)");
$mysql->query("INSERT php_insert_bm(text, count, coords_id) VALUES('', 0, " . $mysql->insert_id . ')');
}
function cycle($c){
global $mysql;
for($i = 0; $i<$c; $i++){
$doc = array(
"text" => "i am any text",
"count" => $i,
"coords" => (object)array("x" => 100, "y" => 200, "z" => $i)
);
$mysql->query('INSERT insert_bm_coords(x,y) VALUES(' . $doc["coords"]->x . ', ' . $doc["coords"]->y . ')');
$mysql->query('INSERT insert_bm(text, count, coords_id) VALUES(' . $doc["text"] . ', ' . $doc["count"] . ', ' . $mysql->insert_id . ')');
}
}
?>