Skip to content

Commit c5e6b20

Browse files
Add new php5+ tests for xml, add xml-data file
1 parent a8a7b3d commit c5e6b20

File tree

4 files changed

+437
-8
lines changed

4 files changed

+437
-8
lines changed

bench.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ function print_pre($msg) {
414414
'26_1_public' => 5000000,
415415
'26_2_getset' => 5000000,
416416
'26_3_magic' => 5000000,
417+
'27_simplexml' => 50000,
418+
'28_domxml' => 50000,
417419
);
418420
$totalOps = 0;
419421

@@ -1013,10 +1015,6 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
10131015
if (extension_loaded('simplexml')) {
10141016
$has_simplexml = "yes";
10151017
}
1016-
$has_xmlreader = "no";
1017-
if (extension_loaded('xmlreader')) {
1018-
$has_xmlreader = "yes";
1019-
}
10201018

10211019
$total = 0;
10221020

@@ -1039,14 +1037,13 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
10391037
. str_pad("PHP memory limit", $padInfo) . " : " . $originMemoryLimit . "\n"
10401038
. str_pad("Memory", $padInfo) . " : " . $memoryLimitMb . ' available' . "\n"
10411039
. str_pad("loaded modules", $padInfo, ' ', STR_PAD_LEFT) . " :\n"
1042-
. str_pad("dom", $padInfo, ' ', STR_PAD_LEFT) . " : $has_dom\n"
10431040
. str_pad("json", $padInfo, ' ', STR_PAD_LEFT) . " : $has_json\n"
10441041
. str_pad("mbstring", $padInfo, ' ', STR_PAD_LEFT) . " : $has_mbstring\n"
1045-
. str_pad("opcache", $padInfo, ' ', STR_PAD_LEFT) . " : $has_opcache\n"
10461042
. str_pad("pcre", $padInfo, ' ', STR_PAD_LEFT) . " : $has_pcre" . ($has_pcre == 'yes' ? '; version: ' . PCRE_VERSION : '') . "\n"
1047-
. str_pad("simplexml", $padInfo, ' ', STR_PAD_LEFT) . " : $has_simplexml\n"
1043+
. str_pad("simplexml", $padInfo, ' ', STR_PAD_LEFT) . " : $has_simplexml; libxml version: ".LIBXML_DOTTED_VERSION."\n"
1044+
. str_pad("dom", $padInfo, ' ', STR_PAD_LEFT) . " : $has_dom\n"
1045+
. str_pad("opcache", $padInfo, ' ', STR_PAD_LEFT) . " : $has_opcache; enabled: ". intval($opcache) . "\n"
10481046
. str_pad("xdebug", $padInfo, ' ', STR_PAD_LEFT) . " : $has_xdebug\n"
1049-
. str_pad("xmlreader", $padInfo, ' ', STR_PAD_LEFT) . " : $has_xmlreader\n"
10501047
. str_pad("Set time limit", $padInfo) . " : " . $maxTime . " sec\n"
10511048
. str_pad("Crypt hash algo", $padInfo) . " : " . $cryptAlgoName . "\n"
10521049
. "$line\n" . $flushStr;

common.inc

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* Common php test functions
4+
* Php 4.4+
45
*/
56

67
/** ---------------------------------- Tests functions -------------------------------------------- */

php5.inc

+69
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,72 @@ function test_26_3_Class_Magic_Methods()
146146
$totalOps += $count;
147147
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
148148
}
149+
150+
// ------------------------- xml -------------------------
151+
152+
function test_27_SimpleXml()
153+
{
154+
global $testsLoopLimits, $totalOps, $emptyResult;
155+
156+
$count = $testsLoopLimits['27_simplexml'];
157+
$time_start = get_microtime();
158+
159+
if (!class_exists('SimpleXMLElement')) {
160+
return $emptyResult;
161+
}
162+
163+
$file = 'test.xml';
164+
if (!is_file($file)) {
165+
return $emptyResult;
166+
}
167+
168+
$xmlStr = file_get_contents($file);
169+
170+
$a = 0;
171+
for ($i = 0; $i < $count; $i++) {
172+
$rss = new SimpleXMLElement($xmlStr);
173+
if ($rss->channel->title == 'PECL: Latest releases') $a++;
174+
if ($rss->item[1]->title == 'rdkafka 5.0.1') $a++;
175+
}
176+
$totalOps += $count;
177+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
178+
}
179+
180+
function test_28_DomXml()
181+
{
182+
global $testsLoopLimits, $totalOps, $emptyResult;
183+
184+
$count = $testsLoopLimits['28_domxml'];
185+
$time_start = get_microtime();
186+
187+
if (!class_exists('DOMDocument')) {
188+
return $emptyResult;
189+
}
190+
191+
$file = 'test.xml';
192+
if (!is_file($file)) {
193+
return $emptyResult;
194+
}
195+
196+
$xmlStr = file_get_contents($file);
197+
198+
$a = 0;
199+
for ($i = 0; $i < $count; $i++) {
200+
$rss = new DOMDocument('1.0', 'utf-8');
201+
$rss->loadXML($xmlStr);
202+
203+
$channel = $rss->getElementsByTagName('channel');
204+
$channel = $channel->item(0);
205+
$chTitle = $channel->getElementsByTagName('title');
206+
$chTitle = $chTitle->item(0);
207+
if ($chTitle->nodeValue == 'PECL: Latest releases') $a++;
208+
209+
$items = $rss->getElementsByTagName('item');
210+
$item = $items->item(1);
211+
$iTitle = $item->getElementsByTagName('title');
212+
$iTitle = $iTitle->item(0);
213+
if ($iTitle->nodeValue == 'rdkafka 5.0.1') $a++;
214+
}
215+
$totalOps += $count;
216+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
217+
}

0 commit comments

Comments
 (0)