简体   繁体   English

Groovy解析JSON与XML

[英]Groovy parsing JSON vs XML

使用groovy,你会期望在读取和查询JSON与XML的速度和内存开销方面有更好的性能吗?

JSON is smaller and simpler than XML. JSON比XML更小,更简单。 I'd bet that JSON is faster to parse. 我敢打赌,解析JSON的速度更快。

YAML would be faster still. YAML会更快。

如果速度确实是一个问题,我宁愿使用java库来解析我想要的东西,而不是依赖于Groovy的实现。

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. 也就是说如果使用错误的XML解析器,你会发现很大的不同。 In other words a SAX implementation could easily match or possibly outperform the JSON parsing. 换句话说,SAX实现可以轻松匹配或可能优于JSON解析。 There are a lot of external factors to cinsider. cinsider有很多外在因素。 If you want the true story throw both a JSON and a SAX parser at the same data/schema with no additional logic. 如果你想要真实的故事,可以在相同的数据/模式中同时抛出JSON和SAX解析器而不需要额外的逻辑。 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. 根据您的要求使用DOM或拉解析器可能更简单,而SAx会导致过于复杂的非性能解决方案。 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. 另一个例子,如果您的XML包含必须通过线路解析的DTD描述和实体引用,并且您的网络连接具有高延迟,那么您可以看到使用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. 由于尖括号和额外信息以及不支持,XML比JSON有更多的开销。 Any good parser should be able to parse JSON faster than XML for this reason. 由于这个原因,任何好的解析器都应该能够比XML更快地解析JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM