性能:XmlSerializer的VS的XmlReader VS XmlDocument的VS的XDocument性能、XmlSerializer、VS、XDocument

2023-09-05 00:00:58 作者:8.何必当初

我正在一个小的网络项目,并想读/写XML文件。性能是我的首要任务。

I'm working on a little web project and would like to read/write to an XML file. Performance is my first priority.

我来这个伟大的帖子比较上除了提到的方法的XmlSerializer

I've come to this great post on comparing the mentioned approaches except XmlSerializer.

我preFER 的XmlSerializer ,因为它使code干净多了。但我不知道它的性能。确实的XmlSerializer 用什么样的里面写XML文件?

I prefer XmlSerializer since it makes the code much cleaner. But I don't know about its performance. What kind does XmlSerializer use inside to write to XML files?

推荐答案

至于XmlSerializer的表现,看到的 http://msdn.microsoft.com/en-us/library/182eeyhh.aspx 它说:

As for the performance of XmlSerializer, see http://msdn.microsoft.com/en-us/library/182eeyhh.aspx which says:

XmlSerializer的创建C#文件和   编译成.dll文件到   执行此序列化。在.NET中   框架2.0,XML序列   生成器工具(Sgen.exe)设计   产生这些序列   预先装配到被部署   您的应用和提高   启动性能。

The XmlSerializer creates C# files and compiles them into .dll files to perform this serialization. In .NET Framework 2.0, the XML Serializer Generator Tool (Sgen.exe) is designed to generate these serialization assemblies in advance to be deployed with your application and improve startup performance.

所以,你可以通过利用SGEN工具 HTTP提高XmlSerializer的性能: //msdn.microsoft.com/en-us/library/bk3w6240.aspx ,这样就能避免性能打你当新的XmlSerializer()创建和编译C#文件。

So you can increase performance of XmlSerializer by making use of the sgen tool http://msdn.microsoft.com/en-us/library/bk3w6240.aspx, that way you can avoid the performance hit you get when new XmlSerializer() creates and compiles C# files.