XMLWriter 与 SimpleXML。哪一个更快?

发布于 2024-09-04 05:35:34 字数 116 浏览 2 评论 0原文

我基本上需要加载整个 XML 文件,添加包含内容的新行,然后保存它。但我想知道哪一个更快.. XMLWriter 还是 SimpleXML?哦,而且,它主要是大型 XML 文件,超过 10MB。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

德意的啸 2024-09-11 05:35:34

根据 PHP 手册,XMLWriter“提供了非缓存,生成包含 XML 数据的流或文件的只进方式。”

它不能用于加载文档并修改它,因此它不是一个选项,您几乎只能使用 SimpleXML。

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.

彼岸花ソ最美的依靠 2024-09-11 05:35:34

我知道这是一个非常古老的问题,但是在研究每种方法的优点时,我偶然发现了这个性能测试:https://p0l0.binware.org/2011/07/04/simplexml-vs-xmlwriter-vs-dom/

摘要:
XMLWriter 是三种方法中最快的,但使用的内存比 SimpleXML 多得多。

一个小文件(大约 2mb)在 XMLWriter 和 SimpleXML 之间并没有显示出很大的差异。 XML 文件越大,两者之间的速度差异就越大,XMLWriter 显然更快。

DOM 是最重、最慢的资源,根本不应该使用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文