-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.php
executable file
·125 lines (94 loc) · 3.28 KB
/
benchmark.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
function bench($message) {
$now = microtime(true);
$mem = memory_get_usage();
fputs(STDOUT, sprintf(" %6.2f %5.1f | %4d %4d | %s\n", ($now-BENCH_START)*1000, ($now-$GLOBALS['bench_last'])*1000, $mem/1024, ($mem-$GLOBALS['mem_last'])/1024, $message));
$GLOBALS['bench_last'] = $now;
$GLOBALS['mem_last'] = $mem;
}
define('BENCH_START', microtime(true));
$GLOBALS['bench_last'] = BENCH_START;
$GLOBALS['mem_last'] = memory_get_usage();
fputs(STDOUT, " ms | KB |\n Total Step | Total Step |\n---------------------------------------------------------\n");
bench('Bench ready');
define('LOOP', 600);
require "tests/bootstrap.php";
bench('Bootstrapped');
class_exists('Dormio_Config');
bench('Dormio_Config include');
$config = new Dormio_Config;
bench('Dormio_Config::instance()');
//$config->addEntities($GLOBALS['test_entities']);
$config->addEntities(include 'docs/examples/entities.php');
bench('addEntities()');
$config->generateAutoEntities();
bench('generateAutoEntities()');
$blog = $config->getEntity('Blog');
bench('getEntity()');
$blog->getField('title');
bench('getField() - default type');
$blog->getField('author');
bench('getField() - foreignkey');
$blog->getField('comments');
bench('getField() - reverse foreignkey');
for($i=0; $i<LOOP; $i++) $blog = $config->getEntity('Blog');
bench('getEntity() multiple');
class_exists('Dormio_Query');
bench('Dormio_Query include');
// query tests
$query = new Dormio_Query($blog, 'sqlite');
bench('Dormio_Query::__construct()');
$query->select();
bench('select() - basic');
$query->filter('author__profile_set__age', '>', 12)->select();
bench('select() - complex filter');
$pdo = new PDO('sqlite::memory:');
foreach(file('docs/examples/entities.sql') as $sql) $pdo->exec($sql);
foreach(file('docs/examples/data.sql') as $sql) $pdo->exec($sql);
bench('Table prepared');
class_exists('Dormio');
bench('Dormio include');
$dormio = new Dormio($pdo, $config);
bench('Dormio::__construct()');
$o = $dormio->getObject('Blog', 2);
assert($o->title == 'Andy Blog 2');
bench('Dormio::getObject()');
for($i=0; $i<LOOP; $i++) {
$o = $dormio->getObject('Blog', 2);
}
assert($o->title == 'Andy Blog 2');
bench('Dormio::getObject() multiple');
$o = $dormio->getObject('Blog');
$o->setValues(array('title'=>'Test', 'body'=>'Testing', 'author'=>1));
$o->save();
assert($o->pk == 4);
bench('Insert one object');
for($i=0; $i<LOOP; $i++) {
$o = $dormio->getObject('Blog');
$o->setValues(array('title'=>'Test ' . $i, 'body'=>'Testing', 'author'=>1));
$o->save();
}
assert($o->pk == LOOP + 4);
//var_dump($o->pk);
bench('Insert multiple objects');
class_exists('Dormio_Manager');
bench('Dormio_Manager include');
$blogs = new Dormio_Manager($blog, $dormio);
bench('Dormio_Manager::__construct() - ARRAY');
$data = $blogs->findArray();
bench('findArray()');
foreach($data as $item) { }
assert($item['title'] == 'Test ' . (LOOP-1));
unset($data);
bench('Array iteration');
$iter = $blogs->find();
bench('find()');
foreach($iter as $item) { $item->title; }
unset($iter);
assert($item->title == 'Test ' . (LOOP-1));
bench('Object iteration');
$result = $blogs->filter('author__profile_set__age', '<', 40)->getAggregator()->count()->run();
assert($result['pk.count'] == LOOP + 3);
bench('Dormio_Aggregator');
assert($blogs->count() == 604);
bench('Dormio_Manager::count()');