Mobile Performance Testing
This article has a look at the performance differences when parsing JSON vs XML. Read on to find out if there's a winner.
Join the DZone community and get the full member experience.Join For Free
It doesn't matter if you're loading a configuration file, data set or even something obtained from a website to use as a data source, there is a performance tradeoff you'll encounter because of the processing time that occurs while parsing JSON or XML. This blog post covers how well loading and reading JSON & XML files using native APIs perform on iOS & Android.
To test performance the SouthWind data set was used for JSON and XML. Both data sets are of roughly the same size, 1.3mb, and contain the same information. Source code used for the performance is provided below. The source for each project is quite generic and simply loads the data set file and reads all the employees into an array. All of the timing information is output through log statements.
Testing was done using a Kindle Fire HDX 7" tablet. The results on Android greatly varied on each run, but JSON was the faster choice by 300 milliseconds and even up to more than a second of processing time.
For XML loading and reading the NSXMLParser class was used. Because of how NSXMLParser is used it required created a separate class and adopting the NSXMLParserDelegate. For JSON loading and reading the NSJSONSerialization class was used for creating an NSDictionary from the JSON.
Testing was done using an iPad 3. The results on iOS were consistent throughout the run and provided JSON quite the edge over XML by more than a second for each of the runs.
As you might of guessed JSON APIs are a lot faster at loading and reading compared to XML APIs. Picking which option to use requires you to look at the entire solution you're working toward. For example, a lot of companies make use of XLST transformations with their XML which can be very powerful. If your app doesn't need a format with a lot of overhead for extra search functionality & transformation, then JSON is the way to go. The open source community has really done a great job extending what's possible with JSON.
Published at DZone with permission of Torrey Betts. See the original article here.
Opinions expressed by DZone contributors are their own.