Jump to content
  • Advertisement
Sign in to follow this  
Sereth

XML vs Text

This topic is 3158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I just have a quick question. I'm working on a game in my spare time, and I'm trying to figure out what the best way to go with something is. I have a large collection of sprites and 2 separate files cataloging them. The first is a text file and the second is an XML file. Both convey the exact same information. The text file is 47kB and difficult to read, I built it with a script and it's definitely not meant to be human readable, though it's relatively easy to process. The XML file is 397kB and a lot easier to read. I know the size is fairly negligible but what about speed? Given the same set of information, is XML significantly faster to process? Processing the text file is purely linear, but I don't know enough about the underlying format of XML. Thanks in advance for any help/advice

Share this post


Link to post
Share on other sites
Advertisement
Don't worry overmuch about speed if you are only going to parse the file once. It's probably more valuable to have a format you can efficiently work with (which might be something in the middle - a more nicely formatted plain text format)

Share this post


Link to post
Share on other sites
I know speed probably isn't a huge concern but I'll probably end up having other data files that might be called more frequently. I think a more nicely formatted text file might be a good option and I may work on that, but can anyone give me an idea of the speed of parsing an XML file vs text (or some other format?). At this point I'm mostly just curious, I think too much modern software (games included) makes a habit of saying "speed isn't a big deal here so just do [something]" and that seems to lead to other problems.

Share this post


Link to post
Share on other sites
Quote:
I think too much modern software (games included) makes a habit of saying "speed isn't a big deal here so just do [something]" and that seems to lead to other problems.


Speed isn't a big deal here, so spend that hour (or other unit of time) optimizing something else -- for example, a bottleneck that you've profiled as being actually important, in desperate need of optimization.

There's a definite counter reaction to your line of thought on these forums: We often think too many people (especially related to gamedev) make a habit of saying "speed is so important I'll just optimize [something]" without bothering to use a profiler to see what would be best to optimize.

And that seems to lead to problems: unreadable code that's often poorly optimized at best, and often slower (anti-optimized!), because "speed is so important" was used as an excuse (conscious or not) to squander precious development time completely unguided by profiling data. And since they weren't using a profiler, they were unable to confirm they were in fact actually optimizing their program instead of slowing it down, nevermind spend their time efficiently.

Cargo cult optimization, in other words.

Sidenote: Also note that while XML tends to 'bloat' filesizes, the duplicative stuff compresses very well using basically any compression algorithm. If you do end up wanting/needing small filesizes, seriously consider that option.

Share this post


Link to post
Share on other sites
I can definitely see that, and that (as you may have guessed) isn't a situation I've run into, so I definitely didn't think of that. What about the situation though, where one design decision that may be less important can sort of ripple. I don't have a lot of experience with this so tell me if this is crazy, but I can see a situation where I decide on one method for data storage here and use that throughout my project. If I choose a slow method here I could see it piling up to the point where i have to redo everything.

I really try to avoid hard coding anything I don't absolutely have to, and part of my project is probably going to be building a system that will let me build and extend various external files to include sets of rules, and at this point I don't know how many, if any, of those are going to be read from more than once in a while or frequently so I want to make sure however I do it works in the best way for multiple situations.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sereth
Can anyone give me an idea of the speed of parsing an XML file vs text (or some other format?).

XML is text. It's text in a specific format. It may be faster or slower than your own format that also uses text, but it's impossible to say without looking at it.

Broadly speaking, any general purpose parser will be slower than a parser made for a specific format. But if your specific format happens to be XML, then the specific parser would work the same way as a general XML parser and the two become equivalent anyway. Do you see why it's impossible to give a proper answer?

Anyway, there is no reason why you can't change the format later if it really becomes a bottleneck. Conversion is usually as easy as loading everything in one way and then saving it out the other way. It's common to support two formats in a project anyway, one for ease of development, one for speed of loading.

Share this post


Link to post
Share on other sites
I would recommend using something like JSON as an alternative. I find it to be much cleaner, simpler, and more tailored to this kind of use.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!