access_time 14 years ago language中文
more_vert

XmlDocumnt与XPathDocument性能对比

visibility 591 comment 0

今天看msdn上说的,如果只读取xml数据,XPathDocument的性能比XmlDocument的要好些,同时用编译了的xpath速度更快,为了测试,今天做了个对比试验,从xml文档循环5000次读取节点的innertext

测试结果如下:分别记录五个 单位均为秒

XPathDocument编译了的Xpath :

8.3069862 8.3542556 8.573382 8.6383464 9.9185413

XPathDocument 没有编译的Xpath:

8.6872359 9.1028773 9.795063 11.651699 8.7361226

貌似两者差别不是特别的大

XmlDocument的测试结果如下:
12.8355047 17.1493918 15.6343026 13.9767847 15.6466003

可见 对于只读 读取xml文档中的内容 最快的确实是XPathDocument并且运用编译的xpath

不过整体速度仍然不能运用在具体的程序中 因为这样一种方式来实现网站的多国语言化会丧失一些性能

现在采取了缓存机制

测试结果非常的好

采用缓存方式的记录结果如下

XPathDocument 的Compile xpath

0.7108073 0.7406044 0.7293728 0.6839916 0.8623431

XPathDocument 没有编译的xpath

0.7796753 0.7228189 0.7436534 0.6883765 0.7283805

XmlDocument

1.0741884 0.8187543 0.6754939 0.5329752 0.5917872 0.650845 0.55835 0.7804511 0.7524811

貌似经过缓存后的XPathDocument速度要快得多?

info Last modified by Raymond 14 years ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Follow Kontext

Get our latest updates on LinkedIn.

Want to contribute on Kontext to help others?

Learn more

More from Kontext

visibility 8956
thumb_up 0
access_time 4 years ago
visibility 34
thumb_up 0
access_time 8 months ago