Comparison of JSON parsers performance on Android

[update2] Tests have been improved with warmup and multiple iterations

[update] I've added also Gson and result are in next post.

On my current project I've already spent some time improving the performance. Further look in Traceview suggested that JSON parsing was eating almost all the time spent during the activity.

I've already switched from Android built-in JSON parser to JSON.simple, because it seemed to be getting less OutOfMemory exceptions (although I can't really confirm this, I saw those also in JSON.simple, coming somewhere from StringBuilder, if I remember correctly) but was also slightly faster. Also JSON.simple usage is almost identical to the built-in one.

Anyway, even with JSON.simple, Traceview was suggesting there could be a better solution. And there was. It is called Jackson and it rocks. It has so-called Streaming API that is not just blazing fast but also promises to keep minimal memory footprint. It is little bit more complicated to use, but it's worth it.

Here are the results of the test on my Nexus One (2.2.2) parsing Twitter's public timeline. It contains 20 object, where each of them has 52 key-value pairs.

  • Android built-in: 277ms
  • JSON.simple: 176ms
  • Jackson: 99ms

Well, quite a difference. JSON.simple takes twice as longer as Jackson and Android built-in parser even three times longer! Sure, it's in this particular test but it roughly corresponds to what I see in my app.

You can have a look at this simple project in my GitHub repository. It is a pretty stupid kind of a comparison (I am not even calling it benchmark :-) and code is not exactly one shining example of an Android app, but it could give you an idea. Also, if you use any other JSON parser in your apps, I would welcome your implementation to the project. Same applies to the comparison logic itself. I am pretty sure one can make it much more detailed and objective.