JSON解释速度对比 - Which parser is fastest on Android?

Correctness and Performance benchmark for various Java-based JSON libraries

Which parser is fastest on Android?

Here's a quick overview from the implementor of Android's two JSON parsers:

  • org.json The API requires you to load the entire document into a String. This is somewhat cumbersome to use and inefficient for large documents. But it's a DOM model so you can get a lot done with very little code.
  • android.util.JsonReader is a basic pull parser. It has a concise API and is reasonably efficient. It's included in Android 3.0. For earlier Android releases it's available as google-gson-stream which offers the same API in a 14 KiB .jar file. The larger GSON library also offers a DOM API and easy databinding.
  • Jackson is efficient and fully-featured. Jackson has a capable but large API. It accomplishes great efficiency by going to some extremes, like implementing its own floating point parsing and charset decoding. If you use Jackson, you may want to use ProGuard to shrink its 222 KiB jar.

As for hard numbers, Jackson has the edge:

  16 Kb Google Reader data:
  JsonReader 2.3 MBps
  Jackson 3.8 MBps

  68 Kb Twitter data:
  JsonReader 2.2 MBps
  Jackson 5 MBps

  185 Kb Google Reader data:
  JsonReader 2.5 MBps
  Jackson 6.5 MBps

Some of the optimizations currently employed by Jackson may be coming to Android.


----------------------------------------------------------------

Jackson 首页 : http://jackson.codehaus.org/Home


下面有一篇更详尽的数据比较,Jackson的优势是明显的:

http://martinadamek.com/2011/02/04/json-parsers-performance-on-android-with-warmup-and-multiple-iterations/


JSON Parsers Performance on Android (With Warmup and Multiple Iterations)

FEB 4TH, 2011

My recent posts on JSON parsers performance on Android platform were followed by some nice feedback. But to be honest, the previous version of the code was not exactly optimal. As @cowtowncoder pointed out in comments, there were several problems.

First and most stupid was that I was using very poor implementation of input reading for Android built-in parser. Now after change in the code, this parser is no longer the slowest one. Next problem was that I did not do any warm-up before actual test were executed. Next Tatu suggested to try to run tests in multiple iterations, so I am running them now 1, 5 and 100 times. I’m also using Jackson factory as static singleton, which is recommended.

Now, let’s see actual results as they appear now:

So it’s Jackson, what you should use if you need really fast reading of JSON data. All the code is up on GitHub.


最终实测:大数据上,jackson比Gson快30%左右,大数据量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值