views:

134

answers:

5

I have some (small amount) of data that I'll need quick access to on inital load, but not after that.

Right now, I have serialized the data (Generic List) to an Xml file and I'm deserializing it on load as needed.

My question is should I use the XmlSerializer or the BinaryFormatter? I'm not worried about file size, but serialization speed.

+2  A: 

BinaryFormatter is faster than XmlSerializer. It has to deal with much less bloated format without string parsing issues.

Mehrdad Afshari
A: 

XML is slow, too much syntax to check. Can you get by with a tab-delimited or CSV file?

Colin Burnett
+1  A: 

"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." -- Don Knuth

If it's a small amount, go with the XmlSerializer even though it's definitely slower. This is one of those small efficiencies that will likely result in swearing when someone tries to look at the file to diagnose a crash.

Jeffrey Hantin
XmlSerializer *without* a serialization assembly is painfully slow the first time. With a pregenerated serialization asm it has acceptable perf.
Mehrdad Afshari
+2  A: 

Interesting answers. I was going to suggest persisting the data as code, and building it into an assembly that would be referenced from the remainder of the application.

John Saunders
A: 

Since John Saunders didn't suggest it, I suggest serializing your static data as code. As a feeble nod to maintainability you could have it reside in an external assembly. This should be the solution with the highest performance and least initial complexity.

If the data is subject to change with any regularity, or is business logic, then ignore this answer. Lest ye be warned!

Robert Venables
That is a very interesting idea, but in my case the data has the posibility to change from deployment to deployment.
Nate Bross