Sunday, January 4, 2015

A JSON Library Comparison

In my ongoing internship opportunity, I came across the use of JSON Strings. This was something I hadn't really paid much attention to before. My mentor told me that it would be a good idea to investigate various JSON Libraries, and decide which would be good to use.
He personally recommended 3 Libraries: GSON, Jackson, and Json.org java library.

I pretty much learnt how to implement the basics of the three in three short days. So if you want to tell me how to improve the tests, feel free to do so.

System Configuration:
Processor: Intel® Core™ i5-2450M CPU @ 2.50GHz × 4
Software: JDK 1.7.0, Eclipse Luna 4.4.1on Kali Linux 1.0.8
The JSON file used is medium.json available in the source directory at Github project page.

The JVM was heated up using 1000 iterations of the program, then from thereon counted the time taken for the next 500 iterations. Then an average of these 500 was taken to give the resultant time of serializing and deserializing.
So here goes, these are for a medium length JSON file that has upto 3 level indentation:

GSON:(211 kB)
Pretty much easy to set up, one single library does it all.
Creation time:0.03006 ms
POJO:
Serializing size:1342
Deserializing size:1312
Deserializing time:0.04008 ms
Serializing time:0.03206 ms
String:
Serializing size:2412
Deserializing size:2189
Deserializing time:0.04409 ms
Serializing time:0.03206 ms

Jackson: (1.3 MB)
Easy to set up, though needs 3 separate libraries to really work. Added afterburner to get faster speed(optional) - another 136 kB
Creation time:0.03206 ms
POJO:
Serializing size:1796
Deserializing size:1796
Deserializing time:0.49298 ms
Serializing time:0.014028 ms
String:
Serializing size:2382
Deserializing size:2189
Deserializing time:0.05811 ms
Serializing time:0.05210 ms


Org.Json java lib: (159 kB)
Quite difficult to manage, and external dependencies are hard to set up. It requires POJO to be set up before parsing, but that's neither here, neither there.
Creation size:0.00601 ms
POJO:
Serializing size:1302
Deserializing size:1758
Deserializing time:0.26853 ms
Serializing time:0.47695 ms

POJO:
From the above, it is clear that if you are after speed, GSON and Jackson are the faster libraries. Jackson has been said to contain a lot of features, though not in the know about the comparison of features right now. While size consumption is much better in the GSON library.
I won't be using Org.Json java library much as it doesn't have many features as it is a small and basic implementation and would probably lead to tearing your hair out. You probably will have to re-implement everything, so would be quite detrimental to your project.
Deserializing time for Jackson is much higher as we are writing to a string, and it takes quite an amount of time. I have learnt that writing to a file takes less time, still have to try that out though.

String:
From the above, it is clear that if you are after speed, GSON and Jackson are the faster libraries. Jackson has been said to contain a lot of features, though not in the know about the comparison of features right now. While size consumption is a tad better in Jackson library.
I couldn't get Org.Json to work without using POJO, so can't comment on that, but the difficulty shies me away from using it much.
Here Gson turns out to be a tad faster than Jackson.

At the end it is a close call, but my vote shall go for use of Jackson due to its much more developed function base and time factor in POJOs, as mostly we do know the type of JSON sent.

Find the work and contribute at: https://github.com/th3dark0n3/json_benchmark

Wednesday, November 19, 2014

Promise to Love

May thy care
Forever Grow
May the new age
Declare eternal love

The age of teens
Freedom to love
Its our time
Make it last

I thank
Thee God
For sending this
angel down below

I promise thee
To treat her
The best
I know how

To you
I promise
All that I am
All that I will be

Tuesday, October 14, 2014

Hackathon

    A Sunday well spent. We, IIITA Firefox Club along with Tech Society, IIITA organized a Hackathon at Indian Institute of Information Technology, Allahabad. The participation was huge for a first time event,with more than 30 teams registered from our college alone. It needed both our blood and sweat to get permission, plan it out and tell people about it.
    There were two general themes presented to the participants, one was Social Welfare and the other was college related help. The ideas were quite exemplary to say the least. The best part was quite surely the brainstorming session. With ideas flowing to and fro, it made me realize the fact that the junior we are college, the more imaginative all of us tend to be. This is a sad fact but rather hard to change because of various reasons that have been discussed for a long time and are well known.
    There were quite nice ideas, some were like integrating the medical system, then there were quite some on the Swachh Bharat Abhiyan. Then some focused on helping the blind. Those are just the ones I know about and helped a little out in. Some actually showed quite a promise as a product that can lead to a good entrepreneurial start-up. As I was mostly focused on helping others out, I just made a small plugin that just counts down to a date. While the idea was to count down to the nearest available blood donation camp date in your locality, I didn't have the requisite time to make it, as most was spent in organization of the event. Possibly, will make it someday soon. For now it's just a timer. You can see it on Blood donation.

There were even two robots build up, one was a search and rescue bot while other was a blind help bot.
     All the code as usual in a Hackathon is owned by the participants for use at their discretion, so you may or may not see some of them. The jury is still out on the Hackathon.