Xml parser performance and Xml generation
am 05.09.2007 17:37:58 von Bastien Continsouzas
Hello,
I need to parse relatively small XML files (less than 100 kB) and to
write XML files that can get quite big (the bigger I can get without
having performance issues, the better).
I looked for benchmark to help me choose beetween existing parser but
didn't manage to find a suitable one. I was looking for something
similar to the following one I found for python :
http://effbot.org/zone/celementtree.htm#benchmarks
I know benchmarks are not perfect but they could help me anyway. For
example, I wonder if SimpleXML uses a lot of memory and is fast
despite its simplicity.
I'd also like to know if writing the XML file using plain strings
would be a lot faster and/or would use a lot less memory than using a
parser to build them. And if I choose this option, what is the fastest
way to build big strings in PHP ?
Thank you,
Bastien
Re: Xml parser performance and Xml generation
am 05.09.2007 18:54:14 von Steve
"Bastien Continsouzas" wrote in message
news:1189006678.130208.175550@19g2000hsx.googlegroups.com...
> Hello,
>
> I need to parse relatively small XML files (less than 100 kB) and to
> write XML files that can get quite big (the bigger I can get without
> having performance issues, the better).
i don't think you'll notice any appreciable difference between parsers with
file sizes that small.
> I'd also like to know if writing the XML file using plain strings
> would be a lot faster and/or would use a lot less memory than using a
> parser to build them. And if I choose this option, what is the fastest
> way to build big strings in PHP ?
it all depends on the xml you are writing. will your output contain
marked-up elements (data typing, etc.) or will it be as simple as:
will it be stand-alone or pull schema info into the mix?
it will always be quicker to put it together yourself...however, doing so
can complicate the maintenance of the script doing the output and you could
be very prone to duplicating your code. that's if your script is written in
procedural contexts.
having said that, you do not need a parser to ever output your xml. to avoid
the afformentioned, you could make appropriate class objects that describe
your data, then give them a toXml() function where you use that information
to build the appropriate output. this is fundamentally different than
procedural code and is what i recommend...especially since you can do so
many other things with the object, like providing a toCsv() interface and
things of that nature including extending the object to create slightly
different variants that may need to 'look' different based on the overall
xml you'd be including it into - it may even depend on having a different
'look' based on the client for whom you are producing it.
just a thought.
Re: Xml parser performance and Xml generation
am 05.09.2007 18:59:26 von Steve
> "Bastien Continsouzas" wrote in message
> news:1189006678.130208.175550@19g2000hsx.googlegroups.com...
>> Hello,
>>
>> I need to parse relatively small XML files (less than 100 kB) and to
>> write XML files that can get quite big (the bigger I can get without
>> having performance issues, the better).
>
> i don't think you'll notice any appreciable difference between parsers
> with file sizes that small.
>
>> I'd also like to know if writing the XML file using plain strings
>> would be a lot faster and/or would use a lot less memory than using a
>> parser to build them. And if I choose this option, what is the fastest
>> way to build big strings in PHP ?
one last thing...if your xml is going to run over your memory constraints,
you'd want to look at writing to file either in chuncks or line by line.
then do with the file what you intend, and then kill it.