What's the difference between downloading xml file using xml.load(url) and downloading the file first, save it and then load it?

StackOverflow https://stackoverflow.com/questions/22493428

質問

and thank you for taking your time to look at my question, I know if there's any kind of performance advantange if instead of using XDocument.Load(Url), I download the file first and then read from it.

For your examples you can use VB.NET or C#, it's all the same for me.

役に立ちましたか?

解決

In general, downloading the file first and saving it will likely be slower than just using XDocument.Load(string). The Load method which accepts a string will stream the contents directly into the XDocument reader, which eliminates extra overhead in the save/read calls. Internally, the Load(string) method creates a Stream and downloads the file, reading from the Stream directly.

However, if the XML document you're loading is static, and you're calling this multiple times, it could (potentially) make sense to cache it locally to avoid the network traffic.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top