-
Notifications
You must be signed in to change notification settings - Fork 23
/
speedtest.php
99 lines (86 loc) · 2.67 KB
/
speedtest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* This file can be used to speedtest OrientDB-PHP library on creating,
* modifying and deleting records.
* Before use, you must create DB named 'speedtest' manually.
*
* @author Anton Terekhov <anton@netmonsters.ru>
* @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011
* @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE
* @link https://github.com/AntonTerekhov/OrientDB-PHP
* @package OrientDB-PHP
* @subpackage Example
*/
require 'OrientDB/OrientDB.php';
$records = 100000;
$time_c = microtime(true);
echo 'Socket' . PHP_EOL;
$db = new OrientDB('localhost', 2424);
echo microtime(true) - $time_c . PHP_EOL;
$time_c = microtime(true);
echo 'OpenDB DB' . PHP_EOL;
$clusters = $db->DBOpen('speedtest', 'admin', 'admin');
echo microtime(true) - $time_c . PHP_EOL;
$time_c = microtime(true);
$result = array();
for ($i = 0; $i < $records; $i++) {
try {
$position = $db->recordCreate(2, 'Name:"Bill",Id:' . $i);
$result[] = $position;
}
catch (OrientDBException $e) {
echo $e->getMessage() . PHP_EOL;
}
}
echo 'Done create ' . $records . PHP_EOL;
echo microtime(true) - $time_c . PHP_EOL;
$callback = function (&$item, $key) {
$item = '#2:' . $item;
};
$time_c = microtime(true);
$linked_records = array();
for ($i = 0; $i < $records / 100; $i++) {
$rand_record = $result[array_rand($result)];
$keys = array_rand($result, $records / 100);
$links = array();
foreach ($keys as $key) {
$links[] = $result[$key];
}
array_walk($links, $callback);
try {
$db->recordUpdate('2:' . $rand_record, 'Name:"Bill",Id:' . $i . ', map:[' . implode(',', $links) . ']');
$linked_records[] = $rand_record;
}
catch (OrientDBException $e) {
echo $e->getMessage() . PHP_EOL;
}
}
echo 'Done update ' . $records . PHP_EOL;
echo microtime(true) - $time_c . PHP_EOL;
$time_c = microtime(true);
$record = $db->recordLoad('2:' . $result[count($result) - 1], '*:-1');
echo 'Done get last' . PHP_EOL;
echo microtime(true) - $time_c . PHP_EOL;
$time_c = microtime(true);
$db->setDebug(true);
try {
$record = $db->recordLoad('2:' . $linked_records[count($linked_records) - 1], '*:10');
}
catch (OrientDBException $e) {
echo $e->getMessage() . PHP_EOL;
}
$db->setDebug(false);
echo 'Done get linked' . PHP_EOL;
echo microtime(true) - $time_c . PHP_EOL;
var_dump($record->content);
$time_c = microtime(true);
for ($i = 0; $i < count($result); $i++) {
try {
$db->recordDelete('2:' . $result[$i]);
}
catch (OrientDBException $e) {
echo $e->getMessage() . PHP_EOL;
}
}
echo 'Done delete ' . $records . PHP_EOL;
echo microtime(true) - $time_c . PHP_EOL;