1: <?php
2: require_once('../qcubed.inc.php');
3:
4: class SpeedForm extends QForm {
5: protected $pnlTiny;
6: protected $pnlBig;
7:
8: protected $btnGo;
9:
10: protected function Form_Create() {
11:
12: $count = 10000;
13: Project::ClearCache();
14: Person::ClearCache();
15:
16:
17:
18:
19: if (Person::CountAll() < $count) {
20: for ($i = 0; $i < $count; $i++) {
21: $objPerson = new Person();
22: $objPerson->FirstName = 'FirstName' . $i;
23: $objPerson->LastName = 'LastName' . $i;
24: $objPerson->Save();
25: }
26: }
27:
28:
29: if (Project::CountAll() < $count) {
30: for ($i = 0; $i < $count; $i++) {
31: $objProject = new Project();
32: $objProject->Name = 'Project' . $i;
33: $objProject->ProjectStatusTypeId = ProjectStatusType::Open;
34: $objProject->ManagerPersonId = $i % 1000 + 1000;
35: $objProject->Description = 'Description' . $i;
36: $objProject->StartDate = QDateTime::Now();
37: $objProject->EndDate = QDateTime::Now();
38: $objProject->Budget = $i;
39: $objProject->Spent = 1;
40: $objProject->Save();
41: }
42: }
43:
44: $this->pnlTiny = new QPanel($this);
45: $this->pnlTiny->Name = '10,000 Person Objects';
46:
47: $this->pnlBig = new QPanel($this);
48: $this->pnlBig->Name = '10,000 Project Objects With Expansion';
49:
50: $this->btnGo = new QButton($this);
51: $this->btnGo->Text = 'Go';
52: $this->btnGo->AddAction (new QClickEvent(), new QAjaxAction('Go_Click'));
53:
54: }
55:
56: protected function Go_Click() {
57: QApplication::$blnLocalCache = false;
58:
59: $timeNoCache = -microtime(true);
60: $a = Person::LoadAll();
61: $timeNoCache += microtime(true);
62:
63: QApplication::$blnLocalCache = true;
64:
65: $timeLoad1Cached = -microtime(true);
66: $a = Person::LoadAll();
67: $timeLoad1Cached += microtime(true);
68: $timeLoad2Cached = -microtime(true);
69: $a = Person::LoadAll();
70: $timeLoad2Cached += microtime(true);
71:
72: QApplication::$blnLocalCache = new QCacheProviderLocalMemory(array());
73:
74: $timeLoad3Cached = -microtime(true);
75: $a = Person::LoadAll();
76: $timeLoad3Cached += microtime(true);
77: $timeLoad4Cached = -microtime(true);
78: $a = Person::LoadAll();
79: $timeLoad4Cached += microtime(true);
80:
81:
82: $this->pnlTiny->Text = sprintf ("Load No Cache: %2.1f%% \n", 100 * $timeNoCache/ $timeNoCache) .
83: sprintf ("Populate Cache: %2.1f%% \n", 100 * $timeLoad1Cached / $timeNoCache) .
84: sprintf ("Load With Cache: %2.1f%% \n", 100 * $timeLoad2Cached / $timeNoCache) .
85: sprintf ("Populate LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad3Cached / $timeNoCache) .
86: sprintf ("Load LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad4Cached / $timeNoCache)
87: ;
88:
89: $cond = QQ::Equal (QQN::Project()->ProjectStatusTypeId, ProjectStatusType::Open);
90: $clauses[] = QQ::Expand (QQN::Project()->ManagerPerson);
91:
92: Project::ClearCache();
93: Person::ClearCache();
94:
95: QApplication::$blnLocalCache = false;
96:
97: $timeNoCache = -microtime(true);
98: $a = Project::QueryArray($cond, $clauses);
99: $timeNoCache += microtime(true);
100:
101: QApplication::$blnLocalCache = true;
102:
103: $timeLoad1Cached = -microtime(true);
104: $a = Project::QueryArray($cond, $clauses);
105: $timeLoad1Cached += microtime(true);
106: $timeLoad2Cached = -microtime(true);
107: $a = Project::QueryArray($cond, $clauses);
108: $timeLoad2Cached += microtime(true);
109:
110: QApplication::$blnLocalCache = new QCacheProviderLocalMemory(array());
111:
112: $timeLoad3Cached = -microtime(true);
113: $a = Project::QueryArray($cond, $clauses);
114: $timeLoad3Cached += microtime(true);
115: $timeLoad4Cached = -microtime(true);
116: $a = Project::QueryArray($cond, $clauses);
117: $timeLoad4Cached += microtime(true);
118:
119:
120: $this->pnlBig->Text = sprintf ("Load No Cache: %2.1f%% \n", 100 * $timeNoCache / $timeNoCache) .
121: sprintf ("Populate Cache: %2.1f%% \n", 100 * $timeLoad1Cached / $timeNoCache) .
122: sprintf ("Load With Cache: %2.1f%% \n", 100 * $timeLoad2Cached / $timeNoCache) .
123: sprintf ("Populate LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad3Cached / $timeNoCache) .
124: sprintf ("Load LocalCacheProvider: %2.1f%% \n", 100 * $timeLoad4Cached / $timeNoCache)
125: ;
126:
127: }
128:
129: }
130: SpeedForm::Run('SpeedForm');
131: ?>