Thursday, 22 August 2013

Jackson 2 VS GSON Performance Comparison

This article discusses a recent performance comparison that I did between Jackson 2.2.2 and GSON 2.2.4.

Disclaimer: This is NOT an attempt to evaluate all aspects of either piece of technology.  I used a specific use case that is applicable to my needs, and ran the comparison.  Your specific use case may differ.

In my use case, I took a very simple object (User with an associated Address object) and converted it to a JSON String (and back) in a varying number of loops using the respective JSON library.  

In my first run-through, I created an instance of the respective JSON library in each iteration of the loop.  This proved to cause a HUGE discrepancy in favour of GSON:

Once I changed this to make the JSON libraries class variables, the results flipped to favour Jackson:

Here is the raw data:

Number of Object ProcessedTime (ms) using Jackson (with Instantiation)Time (ms) using Jackson (without Instantiation)Time (ms) using GSON (with Instantiation)Time (ms) using GSON (without Instantiation)

If your project will be creating an instance of the JSON library on the fly, it would be better to use GSON.  However, if you have an instance of the library already created, Jackson proves to be faster.  As my project is using Spring, it is beneficial to use Jackson, and instantiate the ObjectMapper in the Spring context.  

1 comment: