Question

Using groovy, would you expect better performance in terms of speed and memory overhead to read and query JSON vs XML?

Was it helpful?

Solution

JSON is smaller and simpler than XML. I'd bet that JSON is faster to parse.

YAML would be faster still.

OTHER TIPS

If speed was really an issue, I would rather use a java library to parse whatever I want than to rely on Groovy's implementation.

If it's the same schema and the same information the memory usage will be nearly the same. Performance should be negligible between the two.

I believe the performance difference would be undetectable to anything other than a profiler if the schema and data is the same. That said you could see a big difference if you used the wrong XML parser. In other words a SAX implementation could easily match or possibly outperform the JSON parsing. There are a lot of external factors to cinsider. If you want the true story throw both a JSON and a SAX parser at the same data/schema with no additional logic. The big savings come from the logic used to interpret the parse. It may be simpler to use a DOM or a pull parser depending on your reqs while SAx would cause an overly complicated non-performant solution. Also there are noticeable differences between parsers as well. Add in the variable of file size and you quickly loose scope of what you're actually measuring. Another example, if your XML includes DTD descriptions and entity references that must be resolved over the wire and your network connection has high latency then you could see improvements with JSON. It all boils down to what you are really trying to do.

XML has a bit more overhead than JSON because of the angle brackets and extra information and what not. Any good parser should be able to parse JSON faster than XML for this reason.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top