-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathphp5.inc
372 lines (305 loc) · 8.5 KB
/
php5.inc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
/**
* Special test only for php 5+
* php 4.x cant compile try construction.
*/
/* ------------------------ Additional data ------------------------ */
class PublicProperties
{
public $number = 0;
}
class GetterSetter
{
private $number = 0;
public function getNumber()
{
return $this->number;
}
public function setNumber($new)
{
$this->number = $new;
return $this;
}
}
class MagicMethods
{
private $number = 0;
public function __get($name)
{
if ($name === 'number') {
return $this->number;
}
return null;
}
public function __set($name, $new)
{
if ($name === 'number') {
$this->number = $new;
}
}
}
/* ------------------------ Tests ------------------------ */
function test_21_0_Loop_Exception_None()
{
global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['21_loop_except'];
$time_start = get_microtime();
$a = 0;
for ($i = 0; $i < $count; $i++) {
$a += $i;
if ($i % 10000 == 1) $a = 0;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_21_1_Loop_Exception_Try()
{
global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['21_loop_except'];
$time_start = get_microtime();
$a = 0;
for ($i = 0; $i < $count; $i++) {
try {
$a += $i;
if ($i % 10000 == 1) $a = 0;
} catch (Exception $e) {
}
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_21_2_Loop_Exception_Catch()
{
global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['21_loop_except'];
$time_start = get_microtime();
$a = 0;
for ($i = 0; $i < $count; $i++) {
try {
$a += $i;
if ($i % 10000 == 1) $a = 0;
throw new Exception($i);
} catch (Exception $e) {
}
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_26_1_Class_Public_Properties()
{
global $testsLoopLimits, $totalOps;
$c = new PublicProperties();
$r = 0;
$count = $testsLoopLimits['26_1_public'];
$time_start = get_microtime();
for ($i = 0; $i < $count; $i++) {
$r = $c->number;
$c->number = $r + $i;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_26_2_Class_Getter_Setter()
{
global $testsLoopLimits, $totalOps;
$c = new GetterSetter();
$r = 0;
$count = $testsLoopLimits['26_2_getset'];
$time_start = get_microtime();
for ($i = 0; $i < $count; $i++) {
$r = $c->getNumber();
$c->setNumber($r + $i);
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_26_3_Class_Magic_Methods()
{
global $testsLoopLimits, $totalOps;
$c = new MagicMethods();
$r = 0;
$count = $testsLoopLimits['26_3_magic'];
$time_start = get_microtime();
for ($i = 0; $i < $count; $i++) {
$r = $c->number;
$c->number = $r + $i;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
// ------------------------- xml -------------------------
function test_27_SimpleXml()
{
global $testsLoopLimits, $totalOps, $emptyResult;
$count = $testsLoopLimits['27_simplexml'];
$time_start = get_microtime();
if (!class_exists('SimpleXMLElement', false)) {
return $emptyResult;
}
$file = 'test.xml';
if (!@is_readable($file)) {
return $emptyResult;
}
$xmlStr = file_get_contents($file);
$a = 0;
for ($i = 0; $i < $count; $i++) {
$rss = new SimpleXMLElement($xmlStr);
if ($rss->channel->title == 'PECL: Latest releases') $a++;
if ($rss->item[1]->title == 'rdkafka 5.0.1') $a++;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_28_DomXml()
{
global $testsLoopLimits, $totalOps, $emptyResult;
$count = $testsLoopLimits['28_domxml'];
$time_start = get_microtime();
if (!class_exists('DOMDocument', false)) {
return $emptyResult;
}
$file = 'test.xml';
if (!@is_readable($file)) {
return $emptyResult;
}
$xmlStr = file_get_contents($file);
$a = 0;
for ($i = 0; $i < $count; $i++) {
$rss = new DOMDocument('1.0', 'utf-8');
$rss->loadXML($xmlStr);
$channels = $rss->getElementsByTagName('channel');
/** @var \DOMNodeList $channels */
$channel = $channels->item(0);
/** @var \DOMElement $channel */
$chTitle = $channel->getElementsByTagName('title');
/** @var \DOMNodeList $chTitle */
$chTitle = $chTitle->item(0);
if ($chTitle->nodeValue == 'PECL: Latest releases') $a++;
$items = $rss->getElementsByTagName('item');
/** @var \DOMNodeList $items */
$item = $items->item(1);
/** @var \DOMElement $item */
$iTitle = $item->getElementsByTagName('title');
/** @var \DOMNodeList $iTitle */
$iTitle = $iTitle->item(0);
if ($iTitle->nodeValue == 'rdkafka 5.0.1') $a++;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
// ------------------- DateTime classes ---------------------
function test_29_DateTime()
{
global $testsLoopLimits, $totalOps, $emptyResult;
if (!class_exists('DateTime', false)) {
return $emptyResult;
}
if (!class_exists('DateInterval', false)) {
return $emptyResult;
}
$count = $testsLoopLimits['29_datetime'];
$time_start = get_microtime();
$now = new DateTime();
$day = new DateInterval("P1D");
$year = new DateInterval("P1Y");
$a = 0;
for ($i = 0; $i < $count; $i++) {
$unix = DateTime::createFromFormat("U", $i);
$unix->sub($year);
$unix->add($day);
$diff = $now->diff($unix);
$a += $diff->y % 2;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
// ------------------------- INTL tests -----------------------
/**
* @since 5.3.0
*/
function test_30_Intl_Number_Format()
{
global $testsLoopLimits, $totalOps, $emptyResult;
if (!class_exists('NumberFormatter', false)) {
return $emptyResult;
}
if (!function_exists('numfmt_create')) {
return $emptyResult;
}
$count = $testsLoopLimits['30_intl_number_format'];
$time_start = get_microtime();
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::DECIMAL );
$fmtD = new NumberFormatter( 'ru_RU', NumberFormatter::DURATION );
$fmtC = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
$fmtS = new NumberFormatter( 'en', NumberFormatter::SPELLOUT );
for ($i = 0; $i < $count; $i++) {
$num = $i / 100.;
$fmt->format($num);
$fmtC->formatCurrency($num, 'EUR');
$fmtC->formatCurrency($num, 'RUR');
$fmtD->format($num);
$fmtD->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%in-numerals");
$fmtD->format($num);
$fmtD->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%with-words");
$fmtD->format($num);
$fmtS->format($num);
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
/**
* @since 5.3.0
*/
function test_31_Intl_Message_Format()
{
global $testsLoopLimits, $totalOps, $emptyResult;
if (!class_exists('MessageFormatter', false)) {
return $emptyResult;
}
if (!function_exists('msgfmt_create')) {
return $emptyResult;
}
$count = $testsLoopLimits['31_intl_message_format'];
$time_start = get_microtime();
$fmt = new MessageFormatter("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
$fmt2 = new MessageFormatter('en', 'Found {0, plural, =0 {no result} =1 {one result} other {# results}}');
for ($i = 0; $i < $count; $i++) {
$num = $i / 123.;
$fmt->format(array($i, 123, $num));
$fmt2->format(array($i));
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
/**
* @since: 5.5.0
*/
function test_32_Intl_Calendar()
{
global $testsLoopLimits, $totalOps, $emptyResult;
if (!class_exists('IntlCalendar', false)) {
return $emptyResult;
}
if (!class_exists('IntlTimeZone', false)) {
return $emptyResult;
}
$count = $testsLoopLimits['32_intl_calendar'];
$time_start = get_microtime();
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT());
$a = 0;
for ($i = 0; $i < $count; $i++) {
$num = $i / 100.;
$cal->clear();
$cal->setTime($num);
if ($cal->inDaylightTime()) $a++;
if ($cal->isWeekend()) $a--;
if ($cal->getMinimalDaysInFirstWeek()) $a++;
$cal->add(IntlCalendar::FIELD_MONTH, 1);
$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
if ($cal->inDaylightTime()) $a--;
if ($cal->isWeekend()) $a++;
if ($cal->getMinimalDaysInFirstWeek()) $a--;
}
$totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}