开发者

XMLWriter vs SimpleXML. Which one is faster?

I basicly need开发者_开发百科 to load the whole XML file, add a new line with content and then saving it. But I wondered which one is faster.. XMLWriter or SimpleXML? Oh, and, it's mainly large XML files, more then 10MB.

Thanks!


As per PHP's manual, XMLWriter "provides a non-cached, forward-only means of generating streams or files containing XML data."

It cannot be used to load a document and modify it, therefore it's not an option and you're pretty much left with SimpleXML.


I know this is a very old question but while researching the advantages of each approach, I stumbled over this performance test: https://p0l0.binware.org/2011/07/04/simplexml-vs-xmlwriter-vs-dom/

A summary:
XMLWriter is the fastest of the three approaches, while using dismissably more memory than SimpleXML.

A small file -circa 2mb- does not show a big difference between XMLWriter and SimpleXML. The bigger the XML file gets the bigger the speed difference between the two, with XMLWriter being clearly faster.

DOM is the resource heaviest and slowest and should not be used at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜