Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,492 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,718 people online right now. Registration is fast and FREE... Join Now!




how slow is SimpleXML ?

 
Reply to this topicStart new topic

how slow is SimpleXML ?, SimpleXML vs. multiple strpos, substr, and str_replace

theRemix
3 Mar, 2008 - 05:04 AM
Post #1

D.I.C Regular
***

Joined: 19 Oct, 2005
Posts: 380



Thanked: 2 times
My Contributions
I have a script that parses a page. it does so by using 21 substr, 34 strpos, and 21 str_replace

these functions aren't that slow, but i'm getting 9.886 to 13.045 seconds for script execution.

i was wondering if parsing the page as an xml document, a dom document, or using something like SimpleXML would be faster.
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: How Slow Is SimpleXML ?
3 Mar, 2008 - 07:13 AM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

easy to find out, take that same page you are parsing, and you timer and try it.

from what i have seen it easy and fast(the build into php function), but i have only use for small files.
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: How Slow Is SimpleXML ?
3 Mar, 2008 - 07:19 AM
Post #3

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

this was used to as a config for different file data rows.

basicly it would take the colm names for the config file, and file in the data for proper alignment.

php

<?php
function load_file_format($filename) {
$XMLPARSER = xml_parser_create();
xml_parser_set_option($XMLPARSER, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($XMLPARSER, XML_OPTION_SKIP_WHITE, 1);

$FILEGLOB = file_get_contents($filename);

//echo "<br>Error opening $filename";

xml_parse_into_struct($XMLPARSER, $FILEGLOB, $VALS, $IDX);
xml_parser_free($XMLPARSER);

unset($FILEGLOB);

// The tags we are concerned about are <filetype>
// Check for the opening and ending tags, then lump all the middle
// records together and pass off to the parseformat
foreach ($IDX as $key=>$value) {

//echo print_r($key)."=>".print_r($value)."\r\n";

if ($key == 'filetype') {
$range = $value;
// each pair is the low / high end of the tag
for ($i=0;$i < count($range); $i+=2) {
$offset = $range[$i] + 1;
$len = $range[$i+1] - $offset;
$DB[] = parse_format(array_slice($VALS,$offset,$len));
//run_log("//parse_format(array_slice($VALS,$offset,$len))");
}
} else {
continue;
}
}

return($DB);
}

// takes the passed array and returns it as a FileFormat class
// prefilled with the data in the array
function parse_format($vals) {
for ($i=0; $i < count($vals); $i++) {
$tmp[$vals[$i]["tag"]] = $vals[$i]["value"];
}
return($tmp);
}
?>


This post has been edited by SpaceMan: 3 Mar, 2008 - 07:21 AM
User is offlineProfile CardPM
+Quote Post

theRemix
RE: How Slow Is SimpleXML ?
3 Mar, 2008 - 08:54 PM
Post #4

D.I.C Regular
***

Joined: 19 Oct, 2005
Posts: 380



Thanked: 2 times
My Contributions
i was wondering if anyone has already done that (timed it) or benchmarked the php XML Parser and knows if it is relatively fast, or slow... before actually putting in the time to test it myself.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:44PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month