Without argument, one of the most common used data model is JSON. There are two popular packages used for handling json — first is the stockjson package that comes with default installation of Python, the other one issimplejson which is an optimized and maintained package for Python. The goal of this blog post is to introduce ultrajson or Ultra JSON, a JSON library written mostly in C and built to be extremely fast.
We have done the benchmark on three popular operations — load, loads anddumps. We have a dictionary with 3 keys — id, name and address. We will dump this dictionary using json.dumps() and store it in a file. Then we will use json.loads() and json.load() separately to load the dictionaries from the file. We have performed this experiment on 10000, 50000, 100000,200000, 1000000 dictionaries and observed how much time it takes to perform the operation by each library.
DUMPS OPERATION LINE BY LINE
Here is the result we received using the json.dumps() operations. We have dumped the content dictionary by dictionary.
We notice that json performs better than simplejson but ultrajson wins the game with almost 4 times speedup than stock json.
DUMPS OPERATION (ALL DICTIONARIES AT ONCE)
In this experiment, we have stored all the dictionaries in a list and dumped the list using json.dumps().