Benchmarking JSON vs XML Parsing in Android

I finally found a JSON version of the Google Reader Atom reading list so I decided to see which is faster for Android. The JSON responses are about 25% smaller so they should be faster to download and process overall. For benchmarking I used my G1 as it has the least memory out of my two Android phones.

In Android SAX is supposed to be the fastest way to parse XML and so in Reader Widget Pro 1.4 I started using it (instead of XML Pull parsing) to handle the Atom reading list. Downloading and processing the reading list over Wifi, SAX takes about 85 milliseconds per item. For large lists of 1000 items plus, this actually goes down to 41 milliseconds.

The JSON parsing built into Android does not have streaming functionality yet. Using it would mean downloading the whole reading list into memory which would cause OutOfMemory errors for large lists. To get around this limitation I used json-simple which has streaming built in. Downloading and processing the reading list over Wifi, json-simple takes about 267 milliseconds per item.

So despite having smaller response sizes, overall JSON is 3 times slower! For the foreseeable future I’ll stick with the Atom reading list and SAX. Hopefully a future version of Android will have JSON streaming support built in.

Disclaimer: the benchmarks did not follow a rigorous scientific method and results might differ for other APIs, Android versions, networks and phones.

One reply on “Benchmarking JSON vs XML Parsing in Android”